1

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

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

这两天共提交了18个申请,18个都进入了申请数据库,但是只发送了16封邮件,只有16个if(mail())被触发。这告诉我它不在服务器 SMTP 上,但 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'));
}   
4

1 回答 1

0

这两天共提交了18个申请,18个都进入了申请数据库,但是只发送了16封邮件,只有16个if(mail())被触发。这告诉我它不在服务器 SMTP 上,但 mail() 只是在提交表单时没有触发。

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

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

即使它返回TRUE(意思if是触发),也不能保证邮件会被传递 - 它只是意味着电子邮件被 SMTP 服务器接受以进行传输。

于 2013-09-27T12:07:01.470 回答