通过PHPMailer连接到SMTP服务器

时间:2014-04-29 16:26:42

标签: php email smtp phpmailer

我在使用PHPMailer时遇到了一些问题 - 它无法连接到SMTP服务器。 我使用以下设置:

$mail->Host = "mail.site.com";
$mail->SMTPAuth = true;
$mail->Port = 26;
$mail->Username = "test@site.com";
$mail->Password = "***";

当我尝试连接时 - 我收到错误“SMTP错误:无法连接到SMTP主机”。 我也尝试设置:

$mail->SMTPSecure = 'ssl';
OR
$mail->SMTPSecure = 'tls';

但错误仍然存​​在。

在我的电子邮件客户端(Thunderbird)中设置:

Server - mail.site.com
Port - 26
Secure Connection - STARTTLS
Username - test@site.com

我成功连接并可以发送/接收电子邮件。也通过telnet mail.site.com 26我成功连接。

为什么使用相同的设置我无法连接到服务器?

1 个答案:

答案 0 :(得分:0)

首先你应该read the docs。你确定你应该连接到26端口吗? SMTP通常在端口25(入站)上运行,通常应该在端口587上使用tls发送。