gpt4 book ai didi

PHPMailer 将 Gmail 用作 SMTP 服务器。无法连接到 SMTP 主机。邮件程序错误 : SMTP Error: Could not connect to SMTP host

转载 作者:可可西里 更新时间:2023-10-31 22:11:28 28 4
gpt4 key购买 nike

我正在尝试使用 phpMailer 通过电子邮件向用户发送确认消息。我的代码是这样的:

<?php
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "sender@gmail.com"; // your SMTP username or your gmail username
$mail->Password = "mypasswrord"; // your SMTP password or your gmail password
$from = "webmaster@example.com"; // Reply to this email
$to="receiver@yahoo.com"; // Recipients email ID
$name="Jersey Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

我已经在 php.ini 中启用了 ssl。

PS> sender@gmail.com 是掩码邮箱,保护隐私。但我确实在那部分放了一个真实的电子邮件地址

最佳答案

在你的 php.ini 中确保你已经取消注释行

extension=php_openssl.dll

关于PHPMailer 将 Gmail 用作 SMTP 服务器。无法连接到 SMTP 主机。邮件程序错误 : SMTP Error: Could not connect to SMTP host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6168882/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com