Reputation: 443
I'm using PHPMailer on my website, but it returns an error:
You must provide at least one recipient email address.
The server is running PHP 7. I've checked out the following pages looking for answers:
None of those solved my problem.
This is the way it's set up:
require_once 'lib/phpmailer/PHPMailerAutoload.php';
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;
$m->Host = 'smtp.zoho.com';
$m->Username = '[email protected]';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->From = '[email protected]';
$m->FromName = 'Name';
$m->Subject = 'Testing PHPMailer';
$m->Body = 'Body of the email. Testing PHPMailer.';
if (!$m->send()) {
echo 'Mailer Error: ' . $m->ErrorInfo;
} else {
echo 'Everything OK.';
}
Doing var_dump(PHPMailer::validateAddress('[email protected]'));
returns true
. So the email address doesn't seem to be the issue.
EDIT
Adding $m->AddAddress = [email protected]
doesn't solve the issue. It returns the exact same error.
EDIT 2
Have added $m->addAddress('[email protected]') to the code. I had been doing that wrong. It now returns a 500 error.
EDIT 3
Turns out I mistyped the addAddress in my code (I misplaced a quote, which caused the 500 error). The provided answer stands. I did not properly add a recipient.
My apologies for troubling you with this. I should've more carefully looked at the PHPMailer example provided, instead of blindly following a third part tutorial.
Upvotes: 5
Views: 43177
Reputation: 28911
You haven't added a recipient address. You need to do this:
$m->addAddress('[email protected]');
Take a look at PHPMailer's example:
https://github.com/PHPMailer/PHPMailer#a-simple-example
Upvotes: 5