【问题标题】:PHPmailer: Error: You must provide at least one recipient email addressPHPmailer:错误:您必须提供至少一个收件人电子邮件地址
【发布时间】:2019-01-21 14:34:45
【问题描述】:

我知道有几个类似的线程,但我尝试了所有都没有成功。

$recipient = ($_POST["to"]);
$mail->AddAddress = ($recipient);

这不起作用。我也尝试过许多不同的组合,例如:

$mail->addAddress = ($recipient, 'name');

我也在运行验证地址,它返回 true

var_dump(PHPMailer::validateAddress($recipient));

我仍然收到Error: You must provide at least one recipient email address

有什么建议吗?

【问题讨论】:

  • 很好奇为什么东西周围有括号,($_POST["to"])?
  • $mail->地址 = ($recipient, 'name'); - 更改为 $mail->addAddress($recipient, 'name');
  • 我以前看到过这个确切的错误,这让我怀疑某处有一个页面给出了不好的建议 - 你能给我一个链接到你找到这个代码的地方吗?
  • 我不记得是哪一个了,但肯定是 stackoverflow :p

标签: php email phpmailer


【解决方案1】:

试试这个:

$mail = new PHPMailer;
$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.mysite.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'info@mysite.nl';                 // SMTP username
$mail->Password = 'secure123'; //  SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to
$mail->setFrom('info@mysite.nl', 'My cool website');  // The email address of your site goes here
$mail->addAddress('customer@hotmail.com', 'Important customer');     //Destination address and name

$mail->Subject = 'Just saying hi!'; //Title of your mail
$mail->Body    = '<h1> A test mail </h1>';
$mail->AltBody = 'Mail has been sent!';
if(!$mail->send()) {
    $data = array('mailissend' => false, 'message' => $mail->ErrorInfo);

} else {
    echo json_encode('Email is sended');
}

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多