向多个收件人发送邮件 [英] Sending mail to multiple recipients

查看:164
本文介绍了向多个收件人发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用于从网站联系表单发送电子邮件的PHP代码:

I have this PHP code for sending emails from a website's contact form:

<?php

  if(count($_POST) > 0){

    $userName = $_POST['userName'];
    $userEmail = $_POST['userEmail'];
    $userSubject = $_POST['userSubject'];
    $userMessage = $_POST['userMessage'];
    $header = "Content-Type: text/html\r\nReply-To: $userEmail\r\nFrom: $userEmail <$userEmail>";

    $body = 
    @"Contact sent from website ".$_SERVER['REMOTE_ADDR']." | Day and time ".date("d/m/Y H:i",time())."<br />
    <hr />
    <p><b>Name:</b></p>
    $userName
    <p>———————————</p>
    <p><b>Subject:</b></p>
    $userSubject
    <p>———————————</p>
    <p><b>Mensagem:</b></p>
    $userMessage
    <hr />
    End of message";

    if(mail("email_recipient_1@mailserver.com", "Mensage sent from website", $body, $header)){
      die("true");  
    } else {
        die("Error sending.");  
      }

  }

?>

我需要更改它才能将电子邮件发送给两个收件人:

I need to change it in order to send emails to two recipients:


  • email_recipient_1@mailserver.com

  • email_recipient_2@mailserver.com

...虽然不知道如何。我在哪里放置其他电子邮件?我尝试在 mail()中添加 email_recipient_2@mailserver.com ,但这没用...

... don't know how, though. Where do I put the other e-mail? I tried adding "email_recipient_2@mailserver.com" in the mail() but it didn't work...

感谢。

Pedro

推荐答案

您可以放置​​多个将电子邮件地址添加到字段中,只需在参数字符串内在它们之间添加逗号即可,如下所示:

You can put multiple email addresses into the to field by simply adding a comma between them inside the parameter string like this:

mail("email1@mailserver.com, email2@mailserver.com", // rest of your code

编辑:下面的评论。

您可以使用中的附加标头参数来隐藏多个电子邮件地址mail()按照文档上的功能

you can hide the multiple email addresses by using the additional headers param in the mail() function as per the docs on it:

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

这是 mail()传递的参数:

mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

这篇关于向多个收件人发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆