【发布时间】:2017-12-07 21:12:48
【问题描述】:
这是我的代码,
require_once("PHPMailer/class.PHPMailer.php");
$mail = new PHPMailer();
/* receiver details and message - start */
$toid = "example@gmail.com";
$toname = "Example";
$msg = "First name : ".$_POST["fname"] . "<br>";
$msg .= "Last name : ".$_POST["lname"]. "<br>";;
$msg .= "Email : ".$_POST["email"]. "<br>";;
$msg .= "Mobile : ".$_POST["mobile"]. "<br>";;
$msg .= "Message : ".$_POST["msg"];
$subject = "sample subject";
/* receiver details and message - end */
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPKeepAlive = true;
/* mail smtp configuration - start */
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'test@gmail.com';
$mail->Password = 'xxxxxx';
/* mail smtp configuration - end */
$mail->From = "test@gmail.com";
$mail->FromName = "from name";
$mail->AddAddress($toid, $toname);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->IsHTML(true);
if($mail->Send()){
echo "success";
}else{
echo "Failure";
}
当运行上面的时候,它会抛出
stream_socket_enable_crypto():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:ssl3_get_server_certificate:certificate verify failed in C:\xampp\htdocs\mail\PHPMailer\class.smtp.php 第 200 行
【问题讨论】:
-
我不是 PHP 人,但在 C# 中尝试通过 gmail 发送电子邮件时遇到了类似的问题。在我的请求中设置 SSL=true 后解决。
-
上周出现了一系列类似的问题 - 我怀疑 gmail 更改了许多 PHP 安装中缺少的根证书,因此请尝试更新您的 CA 证书作为故障排除指南和 PHP 文档说。不是这个问题,但是你使用的 PHPMailer 版本很旧,所以获取最新版本。
-
我检查了最新的也抛出了同样的错误@Synchro
-
这就是为什么我说“不是这个问题”。修复你的证书,按照指南所说的去做。