我知道有几个类似的线程,但是我都尝试了所有但都没有成功。
$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
有什么建议吗?
答案 0 :(得分:0)
尝试一下:
$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');
}