Jump to content

Recommended Posts

i want to have this script redirect from -Mail has been sent successfully- after 3 secs back to home page

how could i do this?

scipt:

<?php
ini_set("SMTP","bosmail.nt.com");
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

if (isset($_POST['submit'])) {
$errors = array();

if (empty($_POST['name'])) {
$errors[] = 'You forgot to enter your name.';

}

if (empty($_POST['phone'])) {
$errors[] = 'You forgot to enter your phone number.';

}

if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email.';

}

if (empty($_POST['subject'])) {
$errors[] = 'You forgot to enter the subject.';

}

if (empty($_POST['comments'])) {
$errors[] = 'You forgot to enter comments.';

}

} else {

} 

if (empty($errors)) {

$name = $name; //senders name
$email = $email; //senders e-mail adress
//$recipient = "atomicstructure@gmail.com"; //recipient
$recipient = "copiman@gmail.com"; //recipient
//$recipient = "ravimrk_diya@yahoo.com"; //recipient

$comments = "$comments...\n\n".$phone;
$subject = $subject; //subject
$header = "From: ". $name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $comments, $header); //mail command 
echo "Mail has been sent successfully.";

} else {

echo 'The following error(s) occurred:<br />';
	foreach ($errors as $msg) {
	echo " - $msg<br />\n";
	}
	echo 'Please go back and try again.<br />';
	}



?>

Link to comment
https://forums.phpfreaks.com/topic/126895-solved-redirect/
Share on other sites

<?php
ini_set("SMTP","bosmail.nt.com");
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

if (isset($_POST['submit'])) {
$errors = array();

if (empty($_POST['name'])) {
$errors[] = 'You forgot to enter your name.';

}

if (empty($_POST['phone'])) {
$errors[] = 'You forgot to enter your phone number.';

}

if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email.';

}

if (empty($_POST['subject'])) {
$errors[] = 'You forgot to enter the subject.';

}

if (empty($_POST['comments'])) {
$errors[] = 'You forgot to enter comments.';

}

} else {

} 

if (empty($errors)) {

$name = $name; //senders name
$email = $email; //senders e-mail adress
//$recipient = "atomicstructure@gmail.com"; //recipient
$recipient = "copiman@gmail.com"; //recipient
//$recipient = "ravimrk_diya@yahoo.com"; //recipient

$comments = "$comments...\n\n".$phone;
$subject = $subject; //subject
$header = "From: ". $name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $comments, $header); //mail command 
echo "Mail has been sent successfully.You are being redirected home.";
header('Refresh: 3; url=index.html');


} else {

echo 'The following error(s) occurred:<br />';
	foreach ($errors as $msg) {
	echo " - $msg<br />\n";
	}
	echo 'Please go back and try again.<br />';
	}



?>

Link to comment
https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656431
Share on other sites

Sleep does not always work properly...I find in my code it will pause ALL execution of code for the number of seconds defined, then continue on.

 

What you can, instead, is this:

 

echo '<meta http-equiv="Refresh" content="10">';

 

and replace the "10" with your duration (in seconds)

 

-- Edit --

 

Sorry, I didn't see that the above code has no HTML as part of it...my tip works if you have other HTML in the page and code is going to be executed (such as display a message on the same page, then redirect for a logout or something similar).

Link to comment
https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656477
Share on other sites

Sleep does not always work properly...I find in my code it will pause ALL execution of code for the number of seconds defined, then continue on.

 

That's what sleep() is supposed to do.

 

Yes, but I find that many people on here suggest using it as something that will do this:

 

Processing code.....

 

[tell php to sleep, so it looks like we're loading while playing an animated gif]

 

Finished processing

 

Just warning that sleep does not do that...I don't think that was the intention of the people above, but just an FYI

Link to comment
https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656984
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.