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



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

$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

有什么建议吗?

试试这个:

$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');
}

相关内容

最新更新