PHP 将邮件发送到多个电子邮件地址

2022-08-30 11:05:01

我应该在这个PHP脚本中更改什么代码以将一封电子邮件发送到20多个电子邮件地址

<?php

$email_to = "youremailaddress@yourdomain.com"; // your email address
$email_subject = "Contact Form Message"; // email subject line
$thankyou = "thankyou.htm"; // thank you page

?>

请举个例子。谢谢。


答案 1

为了提高代码的可读性,使用数组并将其内爆为逗号分隔的字符串:-

$recipients = array(
  "youremailaddress@yourdomain.com",
  // more emails
);
$email_to = implode(',', $recipients); // your email address
$email_subject = "Contact Form Message"; // email subject line
$thankyou = "thankyou.htm"; // thank you page

答案 2

$email_to = "address@one.com, address@two.com, address@three.com"

需要是逗号分隔的电子邮件地址列表。

mail($email_to, $email_subject, $thankyou);

推荐