mail()有时不会在表单提交时触发

时间:2013-09-27 12:01:59

标签: php

我继承了一个网站,有一个完整的就业部分,我们经常接到那些发誓他们提交申请的狄更斯的人的电话,我们只是没有得到它。 (HR仅使用通过电子邮件发送给他们的副本,大部分应用程序都已发送到数据库)

通过我所有的调查,我只是不知道为什么它随机有时不起作用。我最近添加了if(mail())提交到一个单独的数据库,以表明它确实发送了邮件。

在过去的两天里,已经提交了18份申请,所有18份申请都被放入了申请数据库,但只发送了16封电子邮件,只有16封(如果(mail())被触发)。这告诉我它不在服务器SMTP上,但mail()只是在提交表单时不会触发。这可能是什么原因?这是mail()代码:

$mailto = "$setting[apps_email]";
$from_name = 'Employment Application';
$from_mail = 'no-reply@....com';
$replyto = 'no-reply@....com';
$uid = md5(uniqid(time())); 
$subject = "".$row[fname]." ".$row[lname]." - ".$row1[position]."";
$filename = "".$row[fname]."".$row[lname]."-".$row[submitted].".pdf";


$header = "From: ".$from_name." <".$from_mail.">".$eol;
$header .= "Reply-To: ".$replyto.$eol;
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"".$eol;
$header .= "Content-Transfer-Encoding: 7bit".$eol;

$message .= "--".$uid.$eol;
$message .= "Content-type:text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message .= $eol."".$row[fname]." ".$row[lname]." has submitted an employment application for the ".$row1[position]." position. Please see the attached .pdf file to save and/or print the application.".$eol;

$message .= "--".$uid.$eol;
$message .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";

$message .= "Content-Disposition: attachment".$eol.$eol;
$message .= $eol.$content;
$message .= "--".$uid."--".$eol;
$fail_date = date('Y-m-d');

if(mail($mailto, $subject, $message, $header)){
    $sql = "INSERT INTO failed_apps (position, name, date, num) values (?, ?, ?, ?)");
    $q = $db->prepare($sql);
    $q->execute(array('$row1[position]', '$_POST[fname] $_POST[lname]', '$fail_date', 'Emailed Succesfully'));
}   

1 个答案:

答案 0 :(得分:0)

  

在过去两天内,已提交了18份申请,全部18份   放入应用程序数据库,但只发送了16封电子邮件   16 if(mail())被触发。这告诉我它不在服务器上   SMTP,但mail()在提交表单时不会触发。

正在发生的事情是mail函数正在返回FALSE,这就是您没有在数据库中看到任何条目的原因。

如果SMTP服务器拒绝发送电子邮件,它将返回FALSE;所以请检查您正在使用的电子邮件服务器的日志。

即使它返回TRUE(意味着,if被触发),也无法保证邮件将被传递 - 这只是意味着SMTP服务器接受了该电子邮件的传输。