2014-01-08 21 views
0

我的PHP的形式與相關聯的每個人的電子郵件地址的<select>選項多個收件人:問題在一個PHP的形式與多個收件人的if語句'

<select name="sendto"> 
    <option value="select">-- Select --</option> 
    <option value="general">General</option> 
    <option value="support">Support</option> 
    <option value="sales">Sales</option> 
</select> 

我能夠發送和成功接收'通用'選項,其餘失敗。很明顯,問題是'如果聲明',但我無法弄清楚問題是什麼。任何幫助?謝謝。

這是PHP代碼:

<?php 
$to = $_REQUEST['sendto'] ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$headers = "From: $from"; 
$subject = "Web Contact Data"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"list"} = "Mailing List"; 
$fields{"Message"} = "Message"; 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.my-site.com"; 


if ($sendto == 'general') { 
    $to = '[email protected]'; 
} 
else if ($sendto == 'support') { 
    $to = '[email protected]'; 
} 
else if ($sendto == 'sales') { 
    $to = '[email protected]'; 
} 
else { //other options 
    $to = '[email protected]'; 
} 

if($from == '') { print "You have not entered an email, please go back and try again"; } 
    else { 
if($name == '') { print "You have not entered a name, please go back and try again"; } 
    else { 
$send = mail($to, $subject, $body, $headers, '[email protected]'); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send){ 
    header("Location: http://www.my-site.com/thankyou.html");} 
else { 
    print "We encountered an error sending your mail, please notify [email protected]"; 
    } 
} 
} 
?> 

回答

2

哪裏是$澡堂定義?這將會「有效」,因爲所有其他人都會失敗,這會違反你的最終條件。

您需要添加這一點,它應該工作

$sendto = $_REQUEST['sendto'] 

或者使用$to insetad