2009-10-06 95 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时遇到问题。