PHP Send-Mail表单到多个电子邮件地址

Wil*_*ard 3 html php forms

我是PHP的新手,我在联系页面上使用基本模板"发送邮件"表单.当点击"提交"按钮时,我被要求将电子邮件发送到多个电子邮件地址.我已经四处寻找并且还没有找到我需要的东西.我需要在下面的表单中添加哪些代码才能将其发送到多个电子邮件地址?

<?php     

$mail_to = 'daniel30293@gmail.com'; // specify your email here


// Assigning data from the $_POST array to variables

$name = $_POST['sender_name'];

$mail_from = $_POST['sender_email'];

$phone = $_POST['sender_phone'];

$web = $_POST['sender_web'];

$company = $_POST['sender_company'];

$addy = $_POST['sender_addy'];

$message = $_POST['sender_message'];


// Construct email subject

$subject = 'Web Prayer Request from ' . $name;


// Construct email body

$body_message = 'From: ' . $name . "\r\n";

$body_message .= 'E-mail: ' . $mail_from . "\r\n";

$body_message .= 'Phone: ' . $phone . "\r\n";

$body_message .= 'Prayer Request: ' . $message;



// Construct email headers

$headers = 'From: ' . $name . "\r\n";

$headers .= 'Reply-To: ' . $mail_from . "\r\n";

$mail_sent = mail($mail_to, $subject, $body_message, $headers);


if ($mail_sent == true){ ?>

<script language="javascript" type="text/javascript">
alert('Your prayer request has been submitted - thank you.');

window.location = 'prayer-request.php';

</script>

<?php } else { ?>

<script language="javascript" type="text/javascript">
alert('Message not sent. Please, notify the site administrator admin@bondofperfection.com');

window.location = 'prayer-request.php';
</script>

<?php

    }

?>
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助.

ajt*_*rds 12

你破坏了一系列收件人:

$recipients = array('jack@gmail.com', 'jill@gmail.com');

mail(implode(',', $recipients), $submit, $message, $headers);
Run Code Online (Sandbox Code Playgroud)

请参阅PHP:Mail函数参考 - http://php.net/manual/en/function.mail.php

收件人或邮件的接收者.

此字符串的格式必须符合»RFC 2822.一些示例是:

  • user@example.com
  • user@example.com, anotheruser@example.com
  • 用户 <user@example.com>
  • 用户<user@example.com>,另一个用户< anotheruser@example.com>