使用phpmailer时没有发送邮件

时间:2009-10-06 05:33:49

标签: php phpmailer

我使用以下代码将邮件发送到smtp服务器。

<?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   = "xxxxx@example.com";  // GMAIL username
$mail->Password   = "xxxx";            // GMAIL password

$mail->From       = "xxxxx@example.com";
$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("xxxxx@example.com","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. 

请有人指导我。

3 个答案:

答案 0 :(得分:1)

显然无法解析主机名mucse491.eu.infineon.com。 使用nslookup,host或其他方法解决问题时,您是否获得了正确的IP地址?

答案 1 :(得分:1)

看起来你有一个PHPMailer版本,可以与旧版本的PHP一起使用。

所以:

1)降级到兼容的较低版本的PHP

2)将PHPMailer升级到更新的版本(如果存在)

3)使用其他邮件库

答案 2 :(得分:1)

您是否尝试将SMTP服务器的IP地址直接放在$mail->Host中?由于某种原因,PHP无法解析您尝试使用的服务器的DNS。