开发者

how do i send a form with php and once the contact info is sent it goes to another url?

what i want to do is when i click on submit it goes to the index page and dont stay on the php page this is my code

$name = $_PO开发者_Go百科ST[\'name\'];
$email = $_POST[\'email\'];
$phone = $_POST[\'phone\'];
$reason = $_POST[\'reason\'];

$header = \'From: \' . $email . \" \\r\\n\";

$msg = \"Sent from: \" . $name . \"\\r\\n\";
$msg .= \"Email: \" . $email . \" \\r\\n\";
$msg .= \"Phone: \" . $phone . \" \\r\\n\";
$msg .= \"Contact reason:\" . $reason . \" \\r\\n\";
$msg .= \"Message: \" . $_POST[\'message\'] . \" \\r\\n\";
$msg .= \"Date and time \" . date(\'d/m/Y\', time());

$to = \'emailhere@something.com\';
$subject = \'contact page\';

mail($to, $subject, utf8_decode($msg), $header);

echo \'The Message is sent\';

i wonder if somebody can help me? i think isnt too hard right?


header("Location: http://www.example.com/");

see http://php.net/manual/de/function.header.php for more info


You can use header("Location: http://www.yoursite.com/index.php") to redirect to the index.php of your website.

The header() method must be called before any issue like the echo \'The Message is sent\';


Why do you escape all those quotes?

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$reason = $_POST['reason'];

$header = 'From: ' . $email . "\r\n";

$msg = "Sent from: " . $name . "\r\n";
$msg .= "Email: " . $email . "\r\n";
$msg .= "Phone: " . $phone . "\r\n";
$msg .= "Contact reason:" . $reason . "\r\n";
$msg .= "Message: " . $_POST['message'] . "\r\n";
$msg .= "Date and time " . date(\'d/m/Y\', time());

$to = 'emailhere@something.com';
$subject = 'contact page';

mail($to, $subject, utf8_decode($msg), $header);

// redirect to page
$url = 'http://example.com';
header('Location: '.$url); // must be used before any output to the browser
die; // prevent execution of other code

You only need to escape quotes you want to display in string.

e.g.:

$test = "This is a \"test\".";

Will display:

This is a "test"

Or you can do:

$test = 'This is a "test"';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜