通过表单发送电子邮件后,我想发送一封邮件,例如发送邮件'或者'错误,重试!'之前将用户重定向到另一个页面。这是我在发送电子邮件后使用的PHP代码:
<?php
[... send mail php code]
$mail->MsgHTML($_POST["message"]);
// this messages are not show, of course
if (!$mail->send()) {
echo '<script language="javascript">';
echo 'alert("Mailer Error: " . $mail->ErrorInfo;)';
echo '</script>';
} else {
echo '<script language="javascript">';
echo 'alert("Message successfully sent. Thank\'s")';
echo '</script>';
}
header( 'Location: http://localhost:8888/contacts.html' ) ;
?>
我该怎么办?
答案 0 :(得分:0)
你可以这样做:
header( "refresh:5; url=http://localhost:8888/contacts.html" );
if(!$mail->send($to, $subject, $body)) {
echo "Didn't send yo";
} else {
echo "Sent";
}
或者这个:
if(!$mail->send($to, $subject, $body)) {
echo "Didn't send yo";
} else {
echo "Sent";
}
sleep(NUMBER_OF_SECONDS);
@header( 'Location: http://localhost:8888/contacts.html' ); //Please note that this method is a big no!!
或者如果PHP没有为你做这件事:
echo "<script>window.setTimeout(function() {window.location.href = 'http://localhost:8888/contacts.html';},NUMBER_OF_SECONDS);</script>";
答案 1 :(得分:0)
试试这个:
<?php
// Mail code goes here
echo 'Successfull';
header( "refresh:5; url=Location: http://localhost:8888/contacts.html" );
?>