2011-11-07 50 views
0

我有一個腳本,我已修改,以滿足我的要求,但我現在需要發送電子郵件給多個人,有人可以指出我在正確的方向,我怎麼可以修改腳本發送給多個人。添加第二個電子郵件地址到腳本

<?php 
if(isset($_POST['email'])) { 

    // EDIT THE 2 LINES BELOW AS REQUIRED 
    $email_to = "[email protected]"; 
    $email_subject = "Kro Catering Website Enquiry"; 


    function died($error) { 
     // your error code can go here 
     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
     echo "These errors appear below.<br /><br />"; 
     echo $error."<br /><br />"; 
     echo "Please go back and fix these errors.<br /><br />"; 
     die(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['your_name']) || 
     !isset($_POST['type']) || 
     !isset($_POST['guests']) || 
     !isset($_POST['date']) || 
     !isset($_POST['phone']) || 
     !isset($_POST['email'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
    } 

    $your_name = $_POST['your_name']; // required 
    $type = $_POST['type']; // required 
    $guests = $_POST['guests']; // required 
    $date = $_POST['date']; // not required 
    $phone = $_POST['phone']; // required 
    $email_from = $_POST['email']; // required 

    $email_message = "Form details below.\n\n"; 

    function clean_string($string) { 
     $bad = array("content-type","bcc:","to:","cc:","href"); 
     return str_replace($bad,"",$string); 
    } 

    $email_message .= "Your Name: ".clean_string($your_name)."\n"; 
    $email_message .= "Type: ".clean_string($type)."\n"; 
    $email_message .= "Guests: ".clean_string($guests)."\n"; 
    $email_message .= "Date: ".clean_string($date)."\n"; 
    $email_message .= "Phone: ".clean_string($phone)."\n"; 
    $email_message .= "Email: ".clean_string($email_from)."\n"; 


// create email headers 
$headers = 'From: '.$email_from."\r\n". 
'Reply-To: '.$email_from."\r\n" . 
'X-Mailer: PHP/' . phpversion(); 
@mail($email_to, $email_subject, $email_message, $headers); 
?> 

<!-- include your own success html here --> 

<?php 

    header('Location: /thanks.aspx') ; 

?> 

<?php 
} 
?> 

回答

2

PHP的mail()功能相當多才多藝,當談到「到「字段。 See the documentation here。列出的任何一個例子就可以了:

[email protected] 
[email protected], [email protected] 
User <[email protected]> 
User <[email protected]>, Another User <[email protected]> 

如此以來,你$email_to變量沒有清洗或以其他方式將其設置在第5行之後修改,你應該能夠只是把2有並由逗號分隔(如上面我從我鏈接到的文檔複製的示例中那樣。)

+0

再次花費額外的時間查看實際文檔,再次燒燬... – jedwards

相關問題