gpt4 book ai didi

php - SMTP 连接失败并激活 TLS

转载 作者:太空宇宙 更新时间:2023-11-03 14:12:04 24 4
gpt4 key购买 nike

我正在使用 PHPMailer 向我的客户发送电子邮件。我想使用 SSL/TLS 发送它们,但这不起作用。我正在使用来自 PHPMailer 的原始示例脚本。当我评论这一行时:$mail->SMTPSecure = 'tls'; 并将凭据更改为我的非 ssl SMTP,它工作正常。否则我会收到此错误:

“消息未发送。邮件程序错误:SMTP connect() 失败。”

我已经用谷歌搜索并发现了类似的问题,其中取消注释 ;extension=php_openssl.dll php.ini 中的这一行有帮助。但是取消注释这对我没有帮助,我检查了 phpinfo() 已经启用了 openssl,所以它应该工作还是?这是我在 phpinfo() 中看到的:http://puu.sh/fyg5Z/a1ab5b0ea5.png

我使用的示例(ofc 使用我自己的 smtp 凭据):

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3; // Enable verbose debug output

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>

我该如何解决?我用我的电子邮件客户端 thunderbird 测试了 SMTP TLS 连接,它运行良好。

最佳答案

我在 phpmailer github 的已关闭问题部分找到了答案。我将引用开发人员 Synchro:

You can't use ssl with port 587. The only combinations that will work are tls/587 and ssl/465, but you should use TLS. It doesn't make any differnce if you site uses http or https.

关于php - SMTP 连接失败并激活 TLS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28369938/

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