如何使用 PHP 将表单数据发送到多个电子邮件地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7377788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send form data to multiple email addresses using PHP?
提问by Wicked Satan
I am a web designer, and dont really know much about PHP. I have a form, and I want the values to be sent to three email addresses.
我是一名网页设计师,并不太了解 PHP。我有一个表单,我希望将值发送到三个电子邮件地址。
Here is my HTML:
这是我的 HTML:
<form id="player" method="post" action="process.php">
<label for="name">Your Name</label>
<input type="text" name="name" title="Enter your name" class="required">
<label for="phone">Daytime Phone</label>
<input type="tel" name="phone" class="required">
<label for="email">Email</label>
<input type="email" name="email" title="Enter your e-mail address" class="required email">
<input type="submit" name="submit" class="button" id="submit" value="I'd like to join Now" />
</form>
I have somehow found a PHP code that should send the data to ONE email address only, but I dont even know if it works or not.
我以某种方式找到了一个 PHP 代码,它应该只将数据发送到一个电子邮件地址,但我什至不知道它是否有效。
Here is the code for that:
这是代码:
<?php
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$url = strip_tags($_POST['url']);
$message = strip_tags($_POST['message']);
// Send Message
mail( "[email protected]", "Contact Form Submission",
"Name: $name\nEmail: $email\nPhone: $phone\nWebsite: $url\nMessage: $message\n",
"From: Forms <[email protected]>" );
?>
Thanks
谢谢
回答by Ahmad Hajjar
Add headers
添加标题
<?php
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$url = strip_tags($_POST['url']);
$message = strip_tags($_POST['message']);
$headers .="From: Forms <[email protected]>";
$headers .="CC: Mail1 <[email protected]>";
$headers .=", Mail2 <[email protected]>";
// Send Message
mail( "[email protected]", "Contact Form Submission",
"Name: $name\nEmail: $email\nPhone: $phone\nWebsite: $url\nMessage: $message\n",
$headers );
?>
回答by Martin Bean
You should be able to separate email addresses with commas in the first parameter of the mail()
function, i.e.
您应该能够在mail()
函数的第一个参数中用逗号分隔电子邮件地址,即
mail('[email protected], [email protected]', $subject, $message, $headers);
Or sepcific CC and optionally BCC addresses as per Ahmad's answer.
或者根据艾哈迈德的回答,特定的抄送地址和可选的密件抄送地址。
回答by Micha? Wojciechowski
The mail
function (which is used in the code that you posted) allows you to specify multiple recipients. See the PHP documentation of that function for details: http://php.net/manual/en/function.mail.php
该mail
函数(在您发布的代码中使用)允许您指定多个收件人。有关详细信息,请参阅该函数的 PHP 文档:http: //php.net/manual/en/function.mail.php
Edit:You basically need to replace the "[email protected]"
part with a list of addresses, separated by commas, e.g.:
编辑:您基本上需要"[email protected]"
用地址列表替换该部分,以逗号分隔,例如:
mail("[email protected],[email protected],[email protected]", ...
回答by helper
use
用
$to = "[email protected]"
$to .= ", [email protected]";
this will help you to create multiple recipient.
这将帮助您创建多个收件人。