向脚本添加第二个电子邮件地址


add a second email address to a script

我有一个脚本,我已经修改,以满足我的要求,但我现在需要发送电子邮件给不止一个人,有人可以指出我在正确的方向,我如何修改脚本发送给一个以上的人。

<?php
if(isset($_POST['email'])) {
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "emailremoved@sample.com";
    $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
}
?>

搜索行:

$email_to = "emailremoved@sample.com";

继续添加用逗号分隔的电子邮件:

$email_to = "emailremoved@sample.com,emailremoved@sample.com,emailremoved@sample.com";

PHP的mail()函数对于"to"字段是非常通用的。请参阅此处的文档。下面列出的任何一个例子都可以:

user@example.com
user@example.com, anotheruser@example.com
User <user@example.com>
User <user@example.com>, Another User <anotheruser@example.com>

因此,由于您的$email_to变量在第5行设置后没有被清理或以其他方式修改,因此您应该能够在那里用逗号分隔2(就像我从链接到的文档中复制的上面的示例一样)

试试这个!这是我唯一能用的代码。

$header .= 'Bcc: someaddress@email.com';