2015-08-08 15 views
1

任何人都可以幫助我找出問題在這裏。我做了很多搜索,並且完成了我發現沒有成功的事情。使用phpmailer與谷歌應用

這裏是我的錯誤,PHPMailer的是最新版本


2015-08-08 13:15:03 Connection: opening to ssl://smtp.mysite.com:465, timeout=300, options=array () 2015-08-08 13:15:04 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-08-08 13:15:04 SMTP connect() failed. 

這裏是我的代碼。

$m = new PHPMailer; 
//Setup 
$m->isSMTP(); 
$m->SMTPAuth = true; 
//authentication 
$m->Host = 'smtp.gmail.com'; 
$m->Username = '[email protected]'; 
$m->Password = 'password'; 
$m->SMTPSecure = 'ssl'; 
$m->Port = 465; 
$m->SMTPDebug = 3;  
//from 
$m->AddReplyTo($email, $name); 
$m->SetFrom('[email protected]', $name); 
//to 
$m->addAddress('[email protected]','guy johnson'); 
$m->addCC('[email protected]','Joe johnson'); 
//message 
$m->Subject = $subject; 
$m->Body = $message; 


if(!$m->Send()) { 
echo"<script type=\"text/javascript\">". 
       "alert('A Error Occured, Please Try Again.');". 
       "</script>"; 
} else { 
echo"<script type=\"text/javascript\">". 
       "alert('Message Sent. Please allow atleast 24-hours for a response');". 
       "window.location='http://example.com';". 
       "</script>"; 
} 

在此先感謝!

+0

確定該端口是否正確? – ajon

+0

@ajon多數民衆贊成它說什麼把我到處看。 – flo

回答

0

您的錯誤消息顯示錯誤中的smtp.example.com,但您的代碼顯示smtp.gmail.com。你嘗試過25端口嗎? Google文檔建議使用SSL進行嘗試。

+0

1)是的,我嘗試了所有3個端口。 2)smtp.gmail.com是用於郵件和/或谷歌應用的gmails服務器,意思是example.com是我的谷歌應用程序電子郵件。 (這是正確的代碼)3)這應該作爲評論發佈而不是答案。 – flo

相關問題