PHPMailer没有发送,但没有错误

时间:2014-01-29 20:44:01

标签: php smtp phpmailer

我在dan.creativeloafing.com上创建了一个php应用程序。这只是获取表单数据并使用它构建一个html页面,然后通过电子邮件将该页面的内容发送到dan@creativeloafing.com。几天前,它停止了工作。从那以后,我一直试图解决这个问题。我正在使用mail()php函数并将其切换到PHPMailer库。这应该是发送电子邮件,我得到确认,但没有人收到电子邮件,我没有得到反弹或任何错误。这是代码的主旨:

//PHPMailer
$mail = new PHPMailer;

$mail->isSMTP();                                    // Set mailer to use SMTP
$mail->Host = 'relay-hosting.secureserver.net';     // Specify main and backup server
$mail->Port = 25; 
$mail->SMTPAuth = false;                            // Enable SMTP authentication
$mail->SMTPSecure = 'tsl';                          // Enable encryption, 'ssl' also accepted
$mail->Username = 'dan@omgsurvey.com';                // SMTP username
$mail->Password = '*******';                         // SMTP password

$mail->SMTPDebug = 0;

$mail->WordWrap = 50;
$mail->From = 'dan@omgsurvey.com';
$mail->FromName = 'DAN Application';
$mail->addAddress('dan@creativeloafing.com');               // Name is optional
$mail->addReplyTo($repEmail);
$mail->addCC('david.miller@creativeloafing.com');

$mail->isHTML(true); 

$mail->Subject = "New DAN Request: ".$campaignName;
$mail->msgHTML(file_get_contents('./tmp/DAN_REQUEST_'.$specialString.$randomNumber.'.html'));

if(!$mail->send()) {
      echo '<br />Proposal could not be sent.<br />';
      echo 'Mailer Error: ' . $mail->ErrorInfo;
      exit;
} else {
  echo 'Proposal has been sent';
}

脚本始终显示“提案已发送”。太。这让我发疯了!

4 个答案:

答案 0 :(得分:1)

所以这里发生的事情就是godaddy阻止了包含我的域名的电子邮件。我不确定这是否是垃圾邮件问题,但他们目前正在研究它。我已经使用简单的mail()函数和电子邮件中删除对omgsurvey.com的任何引用来发送电子邮件。傻,这封邮件只发送到两个电子邮件地址!

答案 1 :(得分:1)

不:

$mail->SMTPSecure = 'tsl';

应该是:

$mail->SMTPSecure = 'tls'; 

答案 2 :(得分:0)

使用try ... catch和PHPMailer(true); https://github.com/Synchro/PHPMailer/blob/master/examples/exceptions.phps

//Create a new PHPMailer instance
//Passing true to the constructor enables the use of exceptions for error handling
$mail = new PHPMailer(true); 

try {

mail->isSMTP();                                    // Set mailer to use SMTP
$mail->Host = 'relay-hosting.secureserver.net';     // Specify main and backup server
$mail->Port = 25; 
$mail->SMTPAuth = false;                            // Enable SMTP authentication
$mail->SMTPSecure = 'tsl';                          // Enable encryption, 'ssl' also accepted
$mail->Username = 'dan@omgsurvey.com';                // SMTP username
$mail->Password = '*******';                          // SMTP password

$mail->SMTPDebug = 0;

$mail->WordWrap = 50;
$mail->From = 'dan@omgsurvey.com';
$mail->FromName = 'DAN Application';
$mail->addAddress('dan@creativeloafing.com');               // Name is optional
$mail->addReplyTo($repEmail);
$mail->addCC('david.miller@creativeloafing.com');

$mail->isHTML(true); 

$mail->Subject = "New DAN Request: ".$campaignName;
$mail->msgHTML(file_get_contents('./tmp/DAN_REQUEST_'.$specialString.$randomNumber.'.html'));

$mail->send();
echo 'Proposal has been sent';

} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer

} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}

答案 3 :(得分:-1)

思考send()应该是Send()

if(!$mail->Send()) {