简体   繁体   English

PHPMailer没有发送,但是没有错误

[英]PHPMailer not sending, but no errors

I created a php application at dan.creativeloafing.com. 我在dan.creativeloafing.com创建了一个php应用程序。 This just takes form data and builds an html page with it, then emails the contents of that page to dan@creativeloafing.com. 这只是获取表单数据并使用它构建一个html页面,然后将该页面的内容通过电子邮件发送至dan@creativeloafing.com。 A couple days ago, it stopped working. 几天前,它停止工作了。 I have been trying to figure this out ever since. 从那时起,我一直在努力解决这个问题。 I was using the mail() php function and have switched it over to the PHPMailer Library. 我正在使用mail()php函数,并将其切换到PHPMailer库。 This is supposedly sending the emails and I get confirmation, but nobody ever recieves the email and I get no bounceback or any errors. 据称这是发送电子邮件,但我得到了确认,但是没有人收到该电子邮件,并且我也没有收到退信或任何错误。 This is the jist of the code: 这是代码的关键:

//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';
}

The script always reaches 'Proposal has been sent.' 脚本始终会到达“提案已发送”。 too. 太。 This is driving me crazy! 这真让我抓狂!

So what was happening here is that godaddy was blocking emails that included my domain name in them. 因此,这里发生的事情是,哥达迪正在阻止包含我的域名的电子邮件。 I am not sure if this was a spam issue, but they are currently looking into it. 我不确定这是否是垃圾邮件问题,但他们目前正在调查中。 I have gotten the emails to send using a simple mail() function and by removing any references to omgsurvey.com in the email. 我已经使用简单的mail()函数并通过删除电子邮件中对omgsurvey.com的任何引用来发送电子邮件。 Silly, this mail was only ever sent to two email addresses! 愚蠢的是,此邮件只发送到两个电子邮件地址!

Isn't: 是不是:

$mail->SMTPSecure = 'tsl';

supposed to be: 应该是:

$mail->SMTPSecure = 'tls'; 

Use try...catch and PHPMailer(true); 使用try ... catch和PHPMailer(true); https://github.com/Synchro/PHPMailer/blob/master/examples/exceptions.phps 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!
}

认为send()应该是Send()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM