PHP邮件程序不在Cpanel中工作

时间:2013-09-09 19:20:14

标签: php cpanel phpmailer

我的php邮件程序上周工作正常,但现在无法正常工作并收到此错误消息:SMTP -> ERROR: Failed to connect to server: Connection refused (111)我不知道出了什么问题,我没有改变任何内容。我正在测试使用我的电子邮件帐户在Outlook中发送电子邮件,结果很好。 我使用的是PHPmailer版本:2.0.4 这是我的代码:

<?php
$btnsubmit      =   $_REQUEST["btnSubmit"];



require_once('class.phpmailer.php');
$mail = new PHPMailer();

$mail->AddEmbeddedImage("images/img1.jpg", "img1", "img1.jpg");


$body             = file_get_contents("promotion.html");
$mail->IsSMTP(); 
$mail->Host       = "smtp.gmail.com"; 
$mail->SMTPDebug  = 1;                
$mail->SMTPAuth   = true; 
$mail->SMTPSecure = "tls";
$mail->Host       = "smtp.gmail.com"; 
$mail->Port       = 465;              
$mail->FromName   = "Administrator"; 
$mail->Username   = "newsletters@laroute-angkor.com"; 
$mail->Password   = "*******";            
$mail->Subject    = "Promotions Tours to Beijing_4D3N_DEPART: 01-OCT-13";
$mail->IsHTML(true);
$mail->MsgHTML($body);



 if( isset($_POST['btnSubmit']))
 {
$mail->AddAddress("msymarina99@yahoo.com", "msymarina99");
$mail->Send();  
echo("SENT COMPLETTED");

}


?>

4 个答案:

答案 0 :(得分:2)

我让它为我工作我有:

$mail->Host       = "mail.drakecomfort.com"; 
$mail->SMTPSecure = "tls";
$mail->Port       = 587;  

将其更改为

$mail->Host       = "smtp.gmail.com"; 
$mail->SMTPSecure = "ssl"; 
$mail->Port       = 465;  

我的最终工作代码:

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                       // 1 = errors and messages
                                       // 2 = messages only
$mail->SMTPAuth   = "true";                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "******@drakecomfort.com";  // GMAIL username
$mail->Password   = "******";            // GMAIL password

$mail->SetFrom('*******@mycomputerstore.com', 'Debrief');

$mail->AddReplyTo("******@mycomputerstore.com","David Ingram");

$mail->Subject    = "$subject";

答案 1 :(得分:0)

某些Cpanel阻止了gmail的端口587或465。你应该在使用phpmailer时尝试其中的一个。

答案 2 :(得分:0)

默认情况下,CPanel会阻止访问外部SMTP服务器。

whm &gt;中停用此限制条件安全中心&gt; SMTP限制禁用

这有效

<?php
require_once('./class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages         only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.mail.yahoo.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxxxx@ymail.com";
$mail->Password = "xxxxxx";
$mail->SetFrom("xxxxx@ymail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("xxxxx@ymail.com");

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

答案 3 :(得分:0)

这对我有用

$mail = new PHPMailer;
$mail->isSMTP(); 
$mail->SMTPDebug = 2; 
$mail->Host = 'Outgoing Server (please add your cpanel of email server) ex: sothing.somthing.com does not required mail word before';
//$mail->Debugoutput = 'html';
$mail->Port       = 587;
$mail->SMTPSecure = 'tls';

$mail->SMTPAuth = true;
$mail->Username = 'your email ex: something.something.com'; 
$mail->Password = 'your password of before mentioned email';
$mail->setFrom('before mentioned email', "something");
$mail->addAddress('receive address (same server email address (cpanel))', "something");
$mail->Subject = 'something';
$mail->msgHTML('something text'); 
//$mail->msgHTML(file_get_contents('contents.html'), __DIR__); 
//Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported';
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
// echo "err";

if(!$mail->send()){
    //echo "Mailer Error: " . $mail->ErrorInfo;
   echo "Ok email send";
}else{
    echo "err";
}