带有 GMail 的 PHPMailer:SMTP 错误

2024-08-23php开发问题
4

本文介绍了带有 GMail 的 PHPMailer:SMTP 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 PHPMailer 通过 GMail 发送邮件.我使用的代码直接来自教程,它可以在我的笔记本电脑上完美运行.但是,在 Windows 2003 Server 上对此进行测试 - 它似乎总是返回一个 SMPT 错误:

I am making use of PHPMailer to send mail through GMail. The code I use is straight from a tutorial and it works perfectly on my laptop. However, testing this on a Windows 2003 Server - it seems to always return an SMPT error:

SMTP 错误:无法连接到 SMTP主持人.邮件程序错误:SMTP 错误:可能未连接到 SMTP 主机.

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

这是我在 PHPMailer 中使用的设置:

Here is the settings I use in PHPMailer:

include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // use ssl
$mail->Host = "smtp.gmail.com"; // GMAIL's SMTP server
$mail->Port = 465; // SMTP port used by GMAIL server

我可以自信地说这不是端口问题,因为我正在连接到端口 465 上的另一台服务器并且它正在发送邮件.如果不是,请解释.

Can I say with confidence that this isn't a port issue, since I am connecting to another server on port 465 and it is sending mail. If not, please explain.

我该如何解决这个问题?

How can I resolve this issue?

感谢大家的帮助

推荐答案

第一件事要注意:Gmail 使用 TLS.不知道用 SSL 代替 TLS 是否会有很大的不同,但 SSL 是 TLS 的前身.

First thing notice off-hand: Gmail uses TLS. Don't know if having SSL instead of TLS will make much of a difference but SSL is the predecessor to TLS.

我还建议检查一下,它的 phpmailer 是为使用 gmail 而定制的.PHPGMailer

I recommend checking out also, its phpmailer customized for using gmail. PHPGMailer

这篇关于带有 GMail 的 PHPMailer:SMTP 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17