PHP Send-Mail表单到多个电子邮件地址 [英] PHP Send-Mail form to multiple email addresses
问题描述
我对PHP很陌生,在联系页面上使用基本模板发送邮件表单。
当点击提交按钮时,我们已经要求将电子邮件发送到多个电子邮件地址。我搜索了&还没有完全找到我需要的东西。我需要在下面的表格中添加什么代码才能将其发送到多个电子邮件地址?
<?php
$ mail_to ='daniel30293@gmail.com'; //在这里指定您的电子邮件
//将数据从$ _POST数组分配给变量
$ 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'];
//构造电子邮件主题
$主题='Web祈祷请求'。 $名称;
//构造邮件正文
$ body_message ='发件人:'。 $名称。 \r\\\
;
$ body_message。='电子邮件:'。 $ mail_from。 \r\\\
;
$ body_message。='电话:'。 $手机。 \r\\\
;
$ body_message。='祈祷请求:'。 $消息;
//构造邮件头
$ headers ='From:'。 $名称。 \r\\\
;
$ headers。='回复:'。 $ mail_from。 \r\\\
;
$ mail_sent = mail($ mail_to,$ subject,$ body_message,$ headers);
if($ mail_sent == true){?>
< script language =javascripttype =text / javascript>
alert('您的祈祷请求已提交 - 谢谢。');
window.location ='prayer-request.php';
< / script>
<?php} else {?>
< script language =javascripttype =text / javascript>
alert('邮件未发送,请通知网站管理员admin@bondofperfection.com');
window.location ='prayer-request.php';
< / script>
<?php
}
?>
非常感谢您的帮助。
您爆炸了一个收件人数组:
$ recipients = array('jack @ gmail .com','jill@gmail.com');
mail(implode(',',$ recipients),$ submit,$ message,$ headers);
请参阅PHP:Mail函数参考 - http://php.net/manual/en/function.mail.php
收件人或邮件的收件人。
此字符串的格式必须符合»RFC 2822.一些示例如下:
-
user@example.com
-
使用者@ example.com
,anotheruser@example.com
- 用户
< user@example.com>
- 用户
< user@example.com>
,另一位用户< ;anotheruser@example.com
>
I'm very new to PHP and am using a basic template 'send-mail' form on a contact page. It's been requested that I send the email out to multiple email addresses when the "Submit" button is clicked. I've searched around & haven't quite found what I needed. What code do I need to add into the form below in order to send this out to multiple email addresses?
<?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
}
?>
Your help is greatly appreciated.
You implode an array of recipients:
$recipients = array('jack@gmail.com', 'jill@gmail.com');
mail(implode(',', $recipients), $submit, $message, $headers);
See the PHP: Mail function reference - http://php.net/manual/en/function.mail.php
Receiver, or receivers of the mail.
The formatting of this string must comply with » RFC 2822. Some examples are:
user@example.com
user@example.com
,anotheruser@example.com
- User
<user@example.com>
- User
<user@example.com>
, Another User <anotheruser@example.com
>
这篇关于PHP Send-Mail表单到多个电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!