2014-01-13 129 views
3

我一直在試圖弄清楚如何讓phpMailer在過去的幾個小時內工作。我不斷收到錯誤。這裏是我的代碼:PHPMailer SMTP連接錯誤

<?php 
$name = $_REQUEST['name'] ; 
$email = $_REQUEST['email'] ; 
$message = $_REQUEST['message'] ; 

require("class.phpmailer.php"); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP 
$mail->SMTPAuth = true; // turn on SMTP authentication 
$mail->Username = "******@gmail.com"; // SMTP username 
$mail->Password = "******"; // SMTP password 
$host = "smtp.mandrillapp.com"; 
$port = 587; 
$mail->SMTPSecure = 'ssl'; 
$mail->SMTPDebug = 1; 
$webmaster_email = "****@gmail.com"; //Reply to this email ID 
$email= $email; // Recipients email ID 
$name= $name; // Recipient's name 
$mail->From = $webmaster_email; 
$mail->FromName = "University of Life Experiences"; 
$mail->AddAddress($email,$name); 
$mail->AddReplyTo($webmaster_email,"Webmaster"); 
$mail->WordWrap = 50; // set word wrap 
$mail->IsHTML(true); // send as HTML 
$mail->Subject = "ULE"; 
$mail->Body = $message; //HTML Body 
$mail->AltBody = $message; //Text Body 
if(!$mail->Send()) 
{ 
echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else 
{ 
echo "Message has been sent"; 
} 
?> 

這裏是我已經收到了錯誤:

SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. Mailer Error: SMTP connect() failed.

我已經嘗試了許多不同的SMTP服務器包括Gmail,我總是得到有關無法連接一個類似的錯誤。

請幫忙,我已經嘗試了很多其他phpMailer示例代碼都具有相同的問題。如果任何人都可以推薦任何其他有用的PHP郵件程序。我不使用內置mail()功能的原因。

+0

你打算從localhost使用這些smtp嗎? – Goikiu

+0

即使使用'SMTPDebug = 1',這就是*所有*信息? –

+0

您使用託管的網絡服務器嗎?也許防火牆阻止端口25.如果你可以通過SSH連接,請嘗試'telnet你服務器smtp'並看看會發生什麼。 – Jens

回答

1

您沒有設置SMTP主機(儘管您聲明變量$host)。通過設置:

$mail->host = $host; 

感謝@Rikesh提醒,$port也是同樣的情況。

邊注意:我注意到你使用gmail.com作爲回覆郵件,但你的SMTP服務器不是Gmail。這可能會導致一些電子郵件服務器將您的電子郵件發送到垃圾郵件/垃圾文件夾

+1

「端口」一樣。 – Rikesh

+0

嘿,謝謝你的答案,但我試過這個,它沒有工作,同樣的錯誤。試圖從WAMP和網絡服務器 – user3051223

+0

你嘗試telnet到SMTP服務器? – Raptor

1

加入試試這個:

$mail->Mailer = "SMTP"; // SMTP Method 

請參考以下鏈接PHP Mailer help

+0

沒有工作,對不起,同樣的錯誤 – user3051223

+0

@Mukil OP已經說過'$ mail-> IsSMTP(); //通過SMTP發送。此外,您提供的鏈接不是官方文檔。 – Raptor

0

嘗試更改端口號

$port = 587; 

$port = 465; 

和檢查什麼新的錯誤喲你越來越,我相信你不會再次發生SMTP連接錯誤。

相關問題