dqp4933 2016-10-10 12:23
浏览 124
已采纳

PHPMailer:您必须至少提供一个收件人电子邮件地址

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@email.com';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;

$m->From = 'email@email.com';
$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@email.com')); returns true. So the email address doesn't seem to be the issue.

EDIT

Adding $m->AddAddress = email@email.com doesn't solve the issue. It returns the exact same error.

EDIT 2

Have added $m->addAddress('email@email.com') 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.

  • 写回答

1条回答 默认 最新

  • douzhanglu4591 2016-10-10 12:24
    关注

    You haven't added a recipient address. You need to do this:

    $m->addAddress('email@email.com');
    

    Take a look at PHPMailer's example:

    https://github.com/PHPMailer/PHPMailer#a-simple-example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同