PHPMailer():在没有连接的情况下调用Mail()

时间:2013-08-26 11:37:04

标签: php email phpmailer

<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
require_once('/PHPMailer/class.phpmailer.php');

$mail=new PHPMailer();
$body='blah body';
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host="127.17.7.4"; // SMTP server
$mail->Port=25;
$mail->SMTPDebug=1;                     // enables SMTP debug information (for testing)
                                               // 1 = errors and messages
                                               // 2 = messages only

$mail->SetFrom('name@zenphoto.com', 'First Last');
$mail->AddReplyTo("name@zenphoto.com","First Last");
$address = "myemail@email.com";  //This will be my email address, that I want to receive the mail on
$mail->AddAddress($address);
$mail->Subject    = "PHPMailer Test Subject via mail(), basic";
$mail->MsgHTML($body);
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>

我正在尝试使用PHPMailer发送邮件,但我一直收到错误: 确切的错误消息:

SMTP - &gt;错误:无法连接到服务器:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机无法响应而建立连接失败。 (10060)

以下发件人地址失败:name@zenphoto.com:调用Mail()而未连接Mailer错误:以下发件人地址失败:name@zenphoto.com:调用Mail()而未连接

1 个答案:

答案 0 :(得分:5)

如果您使用smtp

,这是您需要遵循的格式
$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtpout.secureserver.net';  // Specify main and backup server
$mail->Port = '80';
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '';                            // SMTP username
$mail->Password = '';                           // SMTP password
$mail->SMTPSecure = '';                            // Enable encryption, 'ssl' also accepted


$mail->From = '';
$mail->FromName = '';
$mail->AddAddress('abc@gmail.com', '');  // Add a recipient
$mail->AddReplyTo('', 'reply');
//$mail->AddCC('');
$mail->AddBCC('');

$mail->WordWrap = 50;      
$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = '';
$mail->Body    =  "<!DOCTYPE html>
        <html lang='en-us'>
            <head>
                <meta charset='utf-8'>
                <title></title>

            </head>
            <body>
    <html>";