php mail()两份发送 [英] php mail() two copies sent
问题描述
使用的代码:
//收件人信息
$ to =$ bookernavn< $ mail> ;;
$ from =Visens VennerHillerød< booking@eksample.dk>;
$ subject =Kvittering - $ a_titel - 。 date(j / n-Y,$ a_dato);
$ headers =MIME-Version:1.0。 \r\\\
;
$ headers。=Content-type:text / html; charset = utf-8。 \r\\\
;
$ headers。=From:$ from。 \r\\\
;
$ headers。=Reply-To:$ from。 \r\\\
;
$ headers。=返回路径:$ from。 \r\\\
;
$ headers。=Bcc:$ from。 \r\\\
;
//现在可以发送电子邮件。
mail($ to,$ subject,$ mailmsg,$ headers);
出于一些奇怪的原因,每次发送两封邮件... _
有时候在几分钟之间... _
任何想法?
你不检查表单是否已提交,因此浏览器刷新将再次发送表单数据,并导致再次发送邮件。当用户按下后退按钮时,也会发生这种情况。
发送电子邮件后,您需要执行303重定向以防止重新提交。如果你愿意,你可以重定向到同一个页面。
这被称为发布/重定向/获取模式。
mail );
header('Location:/ some-page-php',true,303);
退出;
I have a simple message that I send using php mail(). The code used:
//recipient info
$to = "$bookernavn <$mail>";
$from = "Visens Venner Hillerød <booking@eksample.dk>";
$subject = "Kvittering - $a_titel - ". date("j/n - Y",$a_dato);
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$headers .= "From: $from" . "\r\n";
$headers .= "Reply-To: $from" . "\r\n";
$headers .= "Return-Path: $from" . "\r\n";
$headers .= "Bcc: $from" . "\r\n";
// now lets send the email.
mail($to, $subject, $mailmsg, $headers); }
For some strange reason two mails are sent each time...
Sometimes with several minutes in between...
Any ideas?
You don't check to see if the form has been submitted so a browser refresh will send the form data again and cause the mail to be sent again. This also happens when a user presses the back button.
After the email is sent you need to do a 303 redirect to prevent the re-submission. You can redirect to the same page if you'd like.
This is called the Post/Redirect/Get pattern.
mail(...);
header('Location: /some-page-php', true, 303);
exit;
这篇关于php mail()两份发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!