2016-04-14 60 views
0

我该如何让gmail从本地主机接受phpmailer并且不阻止登录?发送邮件从本地主机到Gmail

如何解决此错误消息

消息无法sent.Mailer错误:SMTP连接()失败。

<?php 
require 'PHPMailer-master\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 = '[email protected]';     // SMTP username 
$mail->Password = 'valid';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'me'); 
// Add a recipient 
    $mail->addAddress('[email protected]');    // Name is optional 
    $mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 


$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'; 
    } 

    ?> 
+0

你试过25端口吗? – Justinas

+0

什么是您的PHP ..的版本? – Yash

+0

您也可以尝试使用Port 465 SSL https://support.google.com/a/answer/176600?hl=zh-CN – RiggsFolly

回答

0

似乎没有连接到端口587上的Google SMTP。您是否在端口587被阻止的网络中。你可以简单地检查是否有连接可以通过使用这个telnet命令进行:

的telnet smtp.gmail.com 587

Snapshot

您将得到如图快照的响应

的Windows中的Telnet客户端默认是禁用的,需要通过Windows'程序和功能启用:

控制面板 - >程序 - >打开或关闭Windows功能,在弹出的check-mar对话框中k“Telnet客户端”。

或者你可以下载Putty

相关问题