php邮件如何设置多个收件人,PHP表单将电子邮件发送给多个收件人

我有一些PHP代码,用于将表单发送到特定的电子邮件地址。但是,我想在PHP发送时再添加几个电子邮件地址。我怎样才能做到这一点?

if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "email@email.com";

$email_subject = "MVP Nomination";

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.
";

echo $error."
";

echo "Please go back and fix these errors.
";

die();

}

// validation expected data exists

if(!isset($_POST['username']) ||

!isset($_POST['body'])||

!isset($_POST['email'])) {

died('We are sorry, but there appears to be a problem with the form you submitted.');

}

$username = $_POST['username']; // required

$body = $_POST['body']; // required

$email_from = $_POST['email']; // required

$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {

$error_message .= 'The Email Address you entered does not appear to be valid.
';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$username)) {

$error_message .= 'The Username you entered does not appear to be valid.
';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$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 .= "Name: ".clean_string($username)."\n";

$email_message .= "Comments: ".clean_string($body)."\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);

}

header("Location: ThankYou.html"); //Redirect to Thank You HTML page after email is sent

?>​

谢谢。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:数字20 设计师:CSDN官方博客 返回首页
评论
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值