1

我的 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

4 回答 4

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";
于 2013-09-09T22:29:38.603 回答
0

一些 Cpanel 阻止了 gmail 的 587 或 465 端口。使用 phpmailer 时,您应该尝试这两种方法之一。

于 2014-01-24T02:54:01.000 回答
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";
}
于 2020-05-27T05:21:25.590 回答
0

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

whm >安全中心> 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";
}?>
于 2017-01-03T02:53:03.127 回答