我正在使用PHPMailer向我的客户发送电子邮件。我想使用SSL/TLS发送它们,但这不起作用。我正在使用PHPMailer的原始示例脚本。当我评论这一行:$mail->SMTPSecure = 'tls';
并将凭据更改为我的非SSL SMTP它工作正常。否则,我收到此错误:SMTP连接失败,激活TLS
“邮件未发送。邮件程序错误:SMTP连接()失败。”
我已经搜索了一下,发现类似的问题,在php.ini的这条线上取消注释;extension=php_openssl.dll
的帮助。但取消注释这并不能帮助我,我检查了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 = '[email protected]'; // 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 = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$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连接,该工作正常。
确定的端口上? TLS SMTP应使用465. 587是未加密提交的端口。 – 2015-02-06 16:15:44
正如我所说,我用我的正确凭据当然,我在那里使用端口465.这不是肯定的问题。我编辑了示例代码。 – kentor 2015-02-06 16:21:17