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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39958215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:03:01  来源:igfitidea点击:

PHPMailer: You must provide at least one recipient email address

phpemailphpmailer

提问by idix

I'm using PHPMaileron my website, but it returns an error:

我在我的网站上使用PHPMailer,但它返回一个错误:

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:

服务器正在运行 PHP 7。我查看了以下页面以寻找答案:

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.

var_dump(PHPMailer::validateAddress('[email protected]'));回报true。所以电子邮件地址似乎不是问题。

EDIT

编辑

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

添加$m->AddAddress = [email protected]并不能解决问题。它返回完全相同的错误。

EDIT 2

编辑 2

Have added $m->addAddress('[email protected]') to the code. I had been doing that wrong. It now returns a 500 error.

已将 $m->addAddress('[email protected]') 添加到代码中。我一直做错了。它现在返回 500 错误。

EDIT 3

编辑 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.

结果我在我的代码中错误地输入了 addAddress(我错误地放置了一个引号,这导致了 500 错误)。提供的答案成立。我没有正确添加收件人。

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.

很抱歉给您带来麻烦。我应该更仔细地查看提供的 PHPMailer 示例,而不是盲目地遵循第三方教程。

采纳答案by jszobody

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

您尚未添加收件人地址。你需要这样做:

$m->addAddress('[email protected]');

Take a look at PHPMailer's example:

看一下 PHPMailer 的例子:

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

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