2009-10-06 93 views
1

我正在使用以下代碼將郵件發送到smtp服務器。使用phpmailer時郵件未被髮送

<?php 

// example on using PHPMailer with GMAIL 
include("PHPMailer/class.phpmailer.php"); 
include("PHPMailer/class.smtp.php"); // note, this is optional - gets called from main class if not already loaded 

$mail    = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Host  = "mucse491.eu.example.com";  // sets GMAIL as the SMTP server 
$mail->Port  = 143;     // set the SMTP port 
$mail->Username = "[email protected]"; // GMAIL username 
$mail->Password = "xxxx";   // GMAIL password 

$mail->From  = "[email protected]"; 
$mail->FromName = "mithun"; 
$mail->Subject = "This is the subject"; 
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body 
$mail->WordWrap = 50; // set word wrap 

$mail->AddAddress("[email protected]","First Last"); 

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

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

?> 

當我在命令行中運行它,我得到以下錯誤

PHP Deprecated: Function eregi() is deprecated in C:\wamp\www\phpmailer\class.p 
hpmailer.php on line 593 

Deprecated: Function eregi() is deprecated in C:\wamp\www\phpmailer\class.phpmai 
ler.php on line 593 
PHP Warning: fputs() expects parameter 1 to be resource, integer given in C:\wa 
mp\www\phpmailer\class.smtp.php on line 213 

Warning: fputs() expects parameter 1 to be resource, integer given in C:\wamp\ww 
w\phpmailer\class.smtp.php on line 213 
Mailer Error: SMTP Error: Could not connect to SMTP host. 

當我從瀏覽器中,我得到以下錯誤

Deprecated: Function eregi() is deprecated in C:\wamp\www\phpmailer\class.phpmailer.php on line 593 

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in C:\wamp\www\phpmailer\class.smtp.php on line 122 

Warning: fsockopen() [function.fsockopen]: unable to connect to mucse491.xx.example.com:143 (php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server.) in C:\wamp\www\phpmailer\class.smtp.php on line 122 
Mailer Error: SMTP Error: Could not connect to SMTP host. 

請人指導我跑。

+0

'$ mail-> Host =「mucse491.eu.xxxxx.com」; //將GMAIL設置爲SMTP服務器 - 如何將gmail設置爲SMTP服務器? – 2009-10-06 05:43:00

+0

請嘗試SwiftMailer。 – Zed 2009-10-06 05:46:12

+0

相同的代碼適用於gmail smtp服務器。但不適用於我公司的服務器。 – Vidya 2009-10-06 06:34:24

回答

0

顯然主機名稱mucse491.eu.infineon.com無法解析。 當你用nslookup,主機或其他東西解決問題時,你會得到一個正確的IP地址嗎?

+0

是的,當我使用nslookup。我得到正確的IP。 – Vidya 2009-10-06 06:47:07

+0

在PHP腳本運行的機器上? – Zed 2009-10-06 07:03:57

0

看起來像你有一個PHPMailer版本,設計用於使用舊版本的PHP。

所以:

1)降級到更低版本的PHP是兼容

2)升級的PHPMailer到新的版本(如果存在)

3)使用不同的郵件庫

+0

相同的代碼適用於gmail smtp服務器。但不適用於我公司的服務器 – Vidya 2009-10-06 06:38:23

+0

可能代碼適用於不同的SMTP服務器,因爲代碼針對不同的服務器以不同的方式執行。例如,一臺服務器可能需要SMTP身份驗證,另一臺則不需要。因此,您可能會碰到一段對於給定的SMTP通信標準無效的代碼。 – Zak 2010-10-04 21:48:16

+0

大多數PHP庫的另一個優點是它們包含源代碼。繼續,複製粘貼580到610行左右的代碼,在class.phpmailer.php中拋出錯誤。這會更有幫助,因爲它看起來像fputs沒有得到有效的句柄 – Zak 2010-10-04 21:51:52

0

您是否嘗試將IP地址的SMTP服務器直接放入$mail->Host?出於某種原因,PHP在解析您嘗試使用的服務器的DNS時遇到問題。