我正在使用AJAX和PHP发送包含联系表单中数据的电子邮件。我正在使用以下PHP:
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
一切正常,但是如果发送了第一封电子邮件,我还想发送带有新参数的确认电子邮件。我以为我可以在200个响应代码之后设置另一个mail()函数,例如:
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
mail($email, $confirmation_subject, $confirmation_content, $confirmation_headers);
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
但这不会导致发送电子邮件。如果发送了管理员电子邮件,则实施确认电子邮件的正确方法是什么?
当您将标头发送回时,执行基本上会停止。我从来没有看过它的记录,但是我以前对此很感兴趣。尝试切换这两个的顺序:
http_response_code(200);
mail($email, $confirmation_subject, $confirmation_content, $confirmation_headers);
至
mail($email, $confirmation_subject, $confirmation_content, $confirmation_headers);
http_response_code(200);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句