Jump to content

[SOLVED] redirect


ultratek

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 = "[email protected]"; //recipient
$recipient = "[email protected]"; //recipient
//$recipient = "[email protected]"; //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 = "[email protected]"; //recipient
$recipient = "[email protected]"; //recipient
//$recipient = "[email protected]"; //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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.