我正尝试在wamp上使用phpmailer发送电子邮件,但我始终遇到相同的问题:
致命错误:未捕获PHPMailer \ PHPMailer \ Exception:SMTP错误:无法连接到SMTP主机。在1898行的D:\ WAMP \ www \ PHPMailer-master \ src \ PHPMailer.php中
PHPMailer \ PHPMailer \ Exception:SMTP错误:无法连接到SMTP主机。在1898行的D:\ WAMP \ www \ PHPMailer-master \ src \ PHPMailer.php中
我已经看过Google上的每条帖子,但没有一个对我有帮助。
require('D:/WAMP/www/PHPMailer-master/src/PHPMailer.php');
require('D:/WAMP/www/PHPMailer-master/src/Exception.php');
require('D:/WAMP/www/PHPMailer-master/src/SMTP.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
session_start();
$mail = new PHPMailer(true);
$mail -> isSmtp();
$mail -> Host='';
$mail -> SMTPAuth = true;
$mail -> Port = 587;
$mail -> charset = 'UTF-8';
$mail -> SMTPSecure = "tls";
$mail -> SetFrom($envoyeur);
$mail -> AddAddress('XXXXXXXXX@gmail.com');
$mail -> AddReplyTo('no-reply@XXXXXXXX.com');
$mail -> isHTML(true);
$mail -> Subject = $sujet;
$mail -> Body = $texte;
if(!$mail->Send()) {
echo 'Email Failed To Send.';
}
else {
echo 'Email Was Successfully Sent.';
header("Location: mailEnvoye.php");
exit;
}
$mail->SmtpClose();
unset($mail);
有些帖子谈到了$ mail-> Hosts,$ mail-> Port,但我不知道如何处理它们。
非常感谢:)