2011-07-22 33 views
0

這是我的代碼我如何發送一個形式與PHP和一旦聯繫人信息發送它去另一個網址?

$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 = \'[email protected]\'; 
$subject = \'contact page\'; 

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

echo \'The Message is sent\'; 

我不知道我想要做的是,當我點擊提交進入到索引頁面和不留PHP頁面 什麼,如果有人能幫助我嗎?我認爲不是太難?

回答

0

你爲什麼逃避所有這些報價?

$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 = '[email protected]'; 
$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 

您只需要轉義想要在字符串中顯示的引號。

如:

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

顯示:

這是一個 「測試」

或者,你可以這樣做:

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

我剛剛發現所有這些PHP代碼..我真的不知道任何其他方式來做到這一點..但感謝讓我知道! – user857551

0

您可以使用頭(「位置: http://www.yoursite.com/index.php「)重定向到您網站的index.php的 。

header()方法必須在任何問題如echo \'消息發送\'之前被調用;

相關問題