2013-01-09 274 views
2

我有以下的PHP的郵件文件:

<?php $name = $_POST['name']; 
$email = $_POST['email']; 
$choice = $_POST['choice'];$num = $_POST['num']; 
$choice1 = $_POST['choice1'];$num1 = $_POST['num1']; 
$phone= $_POST['phone']; 
$town= $_POST['town']; 
$formcontent=" 
Name: $name \n 
Number: $phone \n 
Choice: $choice Amount:$num 
Choice: $choice1 Amount:$num1 
Town: $town \n 
Email: $email" ; 
$recipient = "[email protected]"; 
$subject = "Contact Form"; 
$mailheader = "From: $email \r\n"; 
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
echo "Thank You!";?> 

我可以添加$電子郵件收件人?我想將表單中輸入的電子郵件添加到收到電子郵件的收件人。 ([email protected]和形式($電子郵件= $ _ POST [「電子郵件」]輸入的電子郵件;)將收到電子郵件

+2

他們逗號分隔,' 「[email protected],」 $ email';豪ver,你會想要確保你清除表單中的數據 - 否則,你將有垃圾郵件機器人濫用那個第一個發現它的東西。 – newfurniturey

+0

它不工作still..its錯誤 –

+0

上面的代碼工作正常。嘗試刪除'或死(「錯誤!」);'看看你得到什麼樣的錯誤,並讓我們知道。 – SeanWM

回答

2

您可以用逗號分隔多個電子郵件地址$recipient加試。這

$recipient = "[email protected], $email"; 

編輯

這裏是整個事情

<?php 

    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $choice = $_POST['choice']; $num = $_POST['num']; 
    $choice1 = $_POST['choice1']; $num1 = $_POST['num1']; 
    $phone= $_POST['phone']; 
    $town= $_POST['town']; 

    $formcontent = " 
    Name: $name \n 
    Number: $phone \n 
    Choice: $choice Amount:$num 
    Choice: $choice1 Amount:$num1 
    Town: $town \n 
    Email: $email"; 

    $recipient = "[email protected], $email"; 
    $subject = "Contact Form"; 
    $mailheader = "From: $email \r\n"; 
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
    echo "Thank you"; 

?> 
+0

它沒有工作=/ –

+0

嗯。你確定所有的值都被髮布了嗎?看到這個鏈接:http://stackoverflow.com/questions/4913817/catching-php-mail-errors-and-showing-reasonable-user-error-message。 –

+0

據我可以看到他們是... –