我应该在这个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
?>
Run Code Online (Sandbox Code Playgroud)
请举个例子.谢谢.
pro*_*son 52
在代码中的前提可读性使用数组并将其内嵌到逗号分隔的字符串: -
$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
Run Code Online (Sandbox Code Playgroud)
Ste*_*n H 31
您的
$email_to = "address@one.com, address@two.com, address@three.com"
Run Code Online (Sandbox Code Playgroud)
需要是逗号分隔的电子邮件地址列表.
mail($email_to, $email_subject, $thankyou);
Run Code Online (Sandbox Code Playgroud)
Pho*_*nix 26
用逗号分隔它们,比如$email_to = "youremailaddress@yourdomain.com, emailtwo@yourdomain.com, John Doe <emailthree@example.com>"
.
raj*_*han 12
以下代码将完成任务....
<?php
$contacts = array(
"youremailaddress@yourdomain.com",
"youremailaddress@yourdomain.com",
//....as many email address as you need
);
foreach($contacts as $contact) {
$to = $contact;
$subject = 'the subject';
$message = 'hello';
mail($to, $subject, $message, $headers);
}
?>
Run Code Online (Sandbox Code Playgroud)
像这样的东西:
mail("john@doe.com , marry@mail.com , frank@domain.com", "Test e-mail", "Hi, this is a test message!");
Run Code Online (Sandbox Code Playgroud)
http://myphpform.com/php-form-multiple-recipients.php
小智 5
将所有电子邮件地址发送给所有收件人是非常不好的做法;您应该使用 Bcc(密件抄送)。
$from = "myname@mymail.com";
$recipList = "mailaddress1,mailaddress2,etc";
$headers = "MIME-Version: 1.0\nContent-type: text/html; charset=utf-8\nFrom: {$from}\nBcc: {$recipList}\nDate: ".date(DATE_RFC2822);
mail(null,$subject,$message,$headers); //send the eail
Run Code Online (Sandbox Code Playgroud)
$recipients = "test1@test.com,test2@test.com,test3@test.com,test1@test.com";
$email_array = explode(",",$recipients);
foreach($email_array as $email)
{
echo $to = $email;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
149358 次 |
最近记录: |