【问题标题】:PHPMailer() + IIS + SMTP = SMTP Error: Could not connect to SMTP hostPHPMailer() + IIS + SMTP = SMTP 错误:无法连接到 SMTP 主机
【发布时间】:2021-04-28 03:57:01
【问题描述】:

我在通过我的 PHP 站点发送电子邮件时遇到了麻烦。我使用下面的代码(尝试了我可以用谷歌搜索的所有内容,但这对我来说最有意义 - 仍然无法正常工作)

$mail = new PHPMailer();
$mail->From = "me@localhost";
$mail->FromName = "My Name";
$mail->AddAddress("someExistingAddress@gmail.com");
$mail->Subject = "Test PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->Subject    = "PHPMailer Test Subject via smtp";
$mail->Host = "localhost"; // SMTP server
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = false;
$mail->Port = 25;
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

执行原因:“SMTP 错误:无法连接到 SMTP 主机”。

我在 Windows 7 上的 IIS (7.5) 上安装了 SMTP,这是我的设置(翻译自波兰语):

SMTP:
地址电子邮件:
me@localhost(那个字段是什么?它甚至不检查正确性,我可以在没有@的情况下输入)
向服务器 SMTP 发送电子邮件:
本地主机
港口:
25
并且不需要身份验证。

Php.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

php_openssl.dll 已启用

请给我一些直接的指导,因为我在无数次试验上浪费了太多时间,但没有成功。

【问题讨论】:

    标签: php iis smtp


    【解决方案1】:

    尝试使用 127.0.0.1 代替 localhost

    【讨论】:

      【解决方案2】:

      您的 php 邮件程序文件是正确的,但您必须使用当前主机。 您可以在 sendgrid 上获得一个免费的 SMTP 帐户进行测试,您可以使用这个 SMTP 帐户。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-04
        • 2012-05-24
        相关资源
        最近更新 更多