Search code examples
phpphpmailer

How to fix undefined method PHPMailer::AddAdress() error?


I am making a PHP mail script, and I'm using phpmailer for it. I get the error:

Fatal error: Call to undefined method PHPMailer::AddAdress() in

This is my code:

if (empty($errors)) {

$m = new PHPMailer;

$m->isSMTP();
$m->SMTPAuth = true;

$m->SMTPdebug = 2;

$m->Host = 'smtp.gmail.com';
$m->Username = 'email@gmail.com';
$m->Password = '******'
$m->SMTPSecure = 'tls';
$m->Port = 465;

$m->isHTML();

$m->Subject = 'Contact form submitted';
$m->Body = 'From: ' . $fields['name'] . ' (' . $fields['email'] . ')<p>' . $fields['message'] . '</p>';

$m->FromName = 'Contact';

$m->AddAdress("email@gmail.com", "Name");

if ($m->send()) {
    header('Location: thanks.php');
    die();
} else {
 $errors[] = 'sorry, could not send';
}

Solution

  • You've missed one d in your method
    Use $m->AddAddress(recipientMailAddress [, recipientName]);