2

我正在使用以下代码将邮件发送到 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. 

请有人指导我。

4

3 回答 3

1

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

于 2009-10-06T05:48:34.743 回答
1

看起来您有一个 PHPMailer 版本,旨在与旧版本的 PHP 一起使用。

所以:

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

或者

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

或者

3) 使用不同的邮件库

于 2009-10-06T05:49:11.653 回答
1

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

于 2009-10-06T07:06:11.933 回答