【问题标题】:phpmailer smtp error while using in online server在在线服务器中使用时phpmailer smtp错误
【发布时间】:2018-07-31 20:19:40
【问题描述】:

这是我的代码...如果我在本地服务器上使用它,它可以正常工作,但是当我在我的服务器上在线使用它时,我收到了这个错误:

无法发送邮件。邮件程序错误:SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

您也可以通过此链接查看:http://khalsasewak.com/mail/

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

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

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

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('raman.singh9718@gmail.com', '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';
}

【问题讨论】:

  • 试试 $mail->端口 = 465;
  • 尝试删除或注释掉$mail-&gt;isSMTP();
  • Sunil Rajput 应该是正确的“端口 465(需要 SSL)”阅读此support.google.com/a/answer/176600?hl=en...
  • 这听起来可能有点激进,但您可以大胆地跳入未知领域并阅读错误消息指向您的文档,这恰好详细回答了这个确切的问题。跨度>

标签: php html server phpmailer


【解决方案1】:

SMTPSecure = 'ssl' 使用端口 465,SMTPSecure = 'tls'; 使用端口 587

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2014-08-03
    • 2014-07-10
    • 2012-12-23
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多