我的PHP電子郵件地址每次頁面刷新時都會發送電子郵件。例如,用戶正在填寫表單並通過發送按鈕發送。這一切都很好,但如果他們刷新頁面,它會再次發送電子郵件與所有相同的表單信息。PHP電子郵件表格每次刷新頁面都會發送電子郵件
我相信這是問題代碼,但不知道它是什麼。
require_once('class.phpmailer.php');
if(isset($_POST['submit'])){
$name = $_POST['name'];
$subject = 'WebForm';
$email = $_POST['email'];
$body = $_POST['message'];
$mail = new PHPMailer;
// $mail->SMTPDebug = 2;
// print_r($_POST);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.office365.com";
$mail->Port = 587;
$mail->Username = "[email protected]";
$mail->Password = "password";
$mailto = "[email protected]";
$mailfrom = "[email protected]";
$mail->SetFrom($mailto, '');
// $mail->AddReplyTo($mailfrom, 'email');
$address = '[email protected]';
$mail->AddAddress($address, "My Addy");
$mail->Subject = $subject;
$mail->AltBody = $body;
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo 'Message has been sent';
}
}
退房這一形象http://upload.wikimedia.org/wikipedia/commons/f/f3/PostRedirectGet_DoubleSubmitProblem.png – Ghost 2014-11-05 04:11:47
你用頭另一頁最佳轉向。 – 2014-11-05 04:14:42