gpt4 book ai didi

php - 邮件不使用 SMTP 通过 SSL 使用 PHPMailer 发送

转载 作者:可可西里 更新时间:2023-11-01 13:02:29 26 4
gpt4 key购买 nike

我正在尝试使用 PHPMailer 通过 SMTP 发送电子邮件,但到目前为止还没有成功。我已经解决了一些 SO 问题、PHPMailer 教程和论坛帖子,但仍然无法正常工作。为了节省时间,我将记录尽可能多的失败尝试,但首先这是我正在使用的代码:

<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors','On');

require('includes/class.phpmailer.php');
include('includes/class.smtp.php');
$mail = new PHPMailer();

$name = $_POST["name"];
$guests = $_POST["guests"];
$time = $_POST["time"];

$message = "<h1>".$name." has booked a table for ".$guests." at ".$time."</h1>";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "myEmail@gmail.com"; // SMTP account username
$mail->Password = "myPassword"; // SMTP account password
$mail->SetFrom('myEmail@gmail.com', 'James Cushing');
$mail->AddReplyTo("myEmail@gmail.com","James Cushing");
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($message)
$address = "myOtherEmail@me.com";
$mail->AddAddress($address, "James Cushing");

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>

首先,当我现在运行这段代码时,我得到了两个不同的错误。在我的本地服务器上出现错误:
SMTP -> 错误:无法连接到服务器:操作超时 (60)
以下发件人地址失败:myEmail@gmail.com:在未连接的情况下调用了 Mail()
邮件程序错误:以下发件人地址失败:myEmail@gmail.com:在未连接的情况下调用了 Mail()

我在我的网络服务器上运行相同的代码时或多或少遇到相同的错误,但第一行是:
SMTP -> 错误:无法连接到服务器:网络无法访问 (101)

显然值得指出的是,我没有使用文字“myEmail@gmail.com”,而是用我自己的电子邮件代替了这篇文章。

我尝试过的事情
- 使用 iCloud SMTP 服务器
- 使用不同的端口
- 在我的 php.ini 文件中启用 OpenSSL 扩展
- 从各种 PHPMailer 示例中复制代码
- 使用谷歌的“DisplayUnlockCaptcha”系统启用连接
- 发送到和从不同的地址 - 从用户名属性中删除“@gmail.com” - 其他一些我不记得的事情

这已经让我发疯了大约一天,所以如果有人能解决这个问题,他们就是英雄。

谢谢

最佳答案

$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "myemail@gmail.com";
$mail->Password = "**********";
$mail->Port = "465";

这是一个有效的配置。

尝试替换你拥有的

关于php - 邮件不使用 SMTP 通过 SSL 使用 PHPMailer 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18535294/

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