2015-08-21 295 views
0

我發送電子郵件從本地主機通過Gmail使用PHP郵件這是我的代碼,但主要問題是,當我運行腳本沒有告訴我任何錯誤,我沒有收到在Gmail ID的任何電子郵件使用PHP郵件發送電子郵件從本地主機到Gmail地址

include("email/class.phpmailer.php"); 
$mail = new PHPMailer(); 
$body = "This is just a Test Email"; 

$mail->IsSMTP(); 

// enable SMTP authentication 
$mail->SMTPAuth = true;     

// sets GMAIL as the SMTP server 
$mail->Host = "smtp.gmail.com"; 

// set the SMTP port for the GMAIL server 
$mail->Port = 465;     

// GMAIL username 
$mail->Username = "Mygmail id"; 

// GMAIL password 
$mail->Password = "password";   
$mail->From  = "Mygmail id"; 
$mail->FromName = "My Name"; 

$mail->Subject = "Testing Message"; 

$mail->AltBody = "To view the message, please use an HTML compatible  
email viewer!"; // optional, comment out and test 
$mail->WordWrap = 50; // set word wrap 

$mail->MsgHTML($body); 

$mail->AddAddress("Receiver Gmail Id"); 

$mail->IsHTML(true); // send as HTML 

if(!$mail->Send()) { 
echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
echo "Message sent!"; 
} 

而且請不要讓我爲重複的問題東陽我嘗試了所有其他的答案,但沒有找到任何解決方案

+0

這是一個重複的內容,[在文檔](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting)中有廣泛的報道,您使用的是舊版本的PHPMailer,並且未能使用[gmail示例提供](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps)。一般來說,它看起來並不像你很努力。 – Synchro

回答

2

服務器:smtp.gmail.com

端口:587

TLS安全

是.... 我已經在幾年前聽說了這個問題,幾個小時後,我花了,我發現我每畝更改端口嘗試改變

+0

意味着我必須在我的文件中包含該代碼$ mail-> SMTPSecure ='tls';並將端口更改爲587和$ mail-> Server ='smtp.gmail.com'; – amansh

+0

這是正確的,但它只是說明了PHPMailer文檔所說的內容,所以它不像是新聞! – Synchro

+0

就我所知,你應該添加/改變它 –

相關問題