我设置了自定义报价功能,可在用户点击提交时向其发送电子邮件。我遇到的问题是,即使您点击“提交”一次,它也会发送两封电子邮件。我在一个WordPress网站上使用它,这段代码是我写的价格报价插件的一部分。
我设置了一个名为$testemail
的变量,设置为1,并且在调用wp_mail
函数时应该增加1,但两个电子邮件仍然只显示数字1,所以第二封电子邮件根本不会增加它。
这是发送电子邮件的代码:
$email_array = array($get_option_array['franchise_email'],
$email_address_sanitize, "info@example.com");
$subject = "Price Quote Submission";
$to = $email_array;
if (isset($_POST['submit-clicked'])) {
if ($check_human_clean != 2) {
echo '<div>';
echo '<p class="error">Human verfication is incorrect. Please try again.</p>';
echo '</div>';
}
else {
if (wp_mail($to, $subject, $message)) {
echo '<div id="dialog" title="Price Quote Submitted">';
echo 'div id="popmake-233">';
echo '<p>Your price quote has been sent successfuly. We\'ll be in touch shortly. If you don\'t hear from us, please give us a call directly at (909) 982-9999. Thank you!</p>';
echo '</div>';
$testemail++;
}
else {
echo '<p class="error">An error occured while processing your price quote. Please contact the franchise owner at ';
echo $get_option_array['franchise_phone'];
echo '</p>';
}
}
}
我读过的所有内容都是代码必须运行两次,但我的$testemail
变量没有递增,所以我不确定是不是这样。此外,我正在使用SendGrid,但我已经尝试关闭SendGrid,但没有解决问题。除此之外,它只使用wp_mail
默认函数,我相信使用PHP Mailer。
我是一名初级开发人员,所以我确定我只是忽略了一些事情,但我很难过。任何帮助都会很棒,谢谢。
答案 0 :(得分:0)
如果$ testemail没有递增,WP中的某些内容可能会分别运行此函数两次,因此$ testemail作为局部变量在第二次运行时不会递增。
以下是一些可能的解决方法:
1)您可以考虑将$ testemail设为全局变量。
2)成功发送电子邮件后,将该事实存储在数据库中。在发送电子邮件之前,请检查数据库以查看是否已发送电子邮件。如果是这样,请不要再发送电子邮件。
3)深入了解WP为什么两次调用此函数。