What code I should do change in this PHP script to send one email to more than 20 email addresses?
我应该在这个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
?>
Please give me an example. Thank you.
请举个例子。谢谢。
12 个解决方案
#1
47
Fore readability sake in the code use an array and implode it to a comma separated string:-
在代码中的前提可读性使用数组并将其内嵌到逗号分隔的字符串: -
$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
25
Just separate them by comma, like $email_to = "youremailaddress@yourdomain.com, emailtwo@yourdomain.com, John Doe <emailthree@example.com>"
.
只需用逗号分隔它们,例如$ email_to =“youremailaddress@yourdomain.com,emailtwo@yourdomain.com,John Doe
#3
21
Your
你的
$email_to = "address@one.com, address@two.com, address@three.com"
Needs to be a comma delimited list of email adrresses.
需要是逗号分隔的电子邮件地址列表。
mail($email_to, $email_subject, $thankyou);
#4
8
Following code will do the task....
以下代码将完成任务....
<?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);
}
?>
#5
5
Something like this:
像这样的东西:
mail("john@doe.com , marry@mail.com , frank@domain.com", "Test e-mail", "Hi, this is a test message!");
http://myphpform.com/php-form-multiple-recipients.php
http://myphpform.com/php-form-multiple-recipients.php
#6
3
$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);
}
#7
2
The best way could be to save all the emails in a database.
最好的方法是将所有电子邮件保存在数据库中。
You can try this code, assuming you have your email in a database
假设您将电子邮件放在数据库中,则可以尝试此代码
/*Your connection to your database comes here*/
$query="select email from yourtable";
$result =mysql_query($query);
/the above code depends on where you saved your email addresses, so make sure you replace it with your parameters/
/上面的代码取决于您保存电子邮件地址的位置,因此请确保将其替换为您的参数/
Then you can make a comma separated string from the result,
然后你可以从结果中创建一个逗号分隔的字符串,
while($row=$result->fetch_array()){
if($rows=='') //this prevents from inserting comma on before the first element
$rows.=$row['email'];
else
$rows.=','.$row['email'];
}
Now you can use
现在你可以使用了
$to = explode(',',$rows); // to change to array
$string =implode(',',$cc); //to get back the string separated by comma
With above code you can send the email like this
使用上面的代码,您可以发送这样的电子邮件
mail($string, "Test", "Hi, Happy X-Mas and New Year");
#8
1
In mail function you can as many reciepient as you want in $emailto paramater seperated by comma.
在邮件功能中,您可以使用逗号分隔的$ emailto paramater中尽可能多的reciepient。
#9
1
It is very bad practice to send all email addresses to all recipients; you should use Bcc (blind carbon copies).
将所有电子邮件地址发送给所有收件人是非常糟糕的做法;你应该使用密送(盲目复印件)。
$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
#10
0
I think the following code will works.
我认为以下代码将有效。
$tos = array('address1@yourdomain.com', 'address2@yourdomain.com');
foreach ($tos as $to){
$ok = mail ($to, $subject, $body, $from);
}
if ($ok) {
echo "Message Send";
} else {
echo "Error";
}
#11
0
Try this. It works for me.
尝试这个。这个对我有用。
$to = $email1 .','. $email2 .','. $email3;
#12
-2
Programmatically sending an submitted form to multiple email address is a possible thing, however the best practice for this is by creating a mailing list. On the code the list address will be place and any change or update on email addresses to the recipients list can be done without changing in the code.
以编程方式将提交的表单发送到多个电子邮件地址是可能的,但最好的做法是创建一个邮件列表。在代码上将放置列表地址,并且可以在不更改代码的情况下完成对收件人列表的电子邮件地址的任何更改或更新。
#1
47
Fore readability sake in the code use an array and implode it to a comma separated string:-
在代码中的前提可读性使用数组并将其内嵌到逗号分隔的字符串: -
$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
25
Just separate them by comma, like $email_to = "youremailaddress@yourdomain.com, emailtwo@yourdomain.com, John Doe <emailthree@example.com>"
.
只需用逗号分隔它们,例如$ email_to =“youremailaddress@yourdomain.com,emailtwo@yourdomain.com,John Doe
#3
21
Your
你的
$email_to = "address@one.com, address@two.com, address@three.com"
Needs to be a comma delimited list of email adrresses.
需要是逗号分隔的电子邮件地址列表。
mail($email_to, $email_subject, $thankyou);
#4
8
Following code will do the task....
以下代码将完成任务....
<?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);
}
?>
#5
5
Something like this:
像这样的东西:
mail("john@doe.com , marry@mail.com , frank@domain.com", "Test e-mail", "Hi, this is a test message!");
http://myphpform.com/php-form-multiple-recipients.php
http://myphpform.com/php-form-multiple-recipients.php
#6
3
$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);
}
#7
2
The best way could be to save all the emails in a database.
最好的方法是将所有电子邮件保存在数据库中。
You can try this code, assuming you have your email in a database
假设您将电子邮件放在数据库中,则可以尝试此代码
/*Your connection to your database comes here*/
$query="select email from yourtable";
$result =mysql_query($query);
/the above code depends on where you saved your email addresses, so make sure you replace it with your parameters/
/上面的代码取决于您保存电子邮件地址的位置,因此请确保将其替换为您的参数/
Then you can make a comma separated string from the result,
然后你可以从结果中创建一个逗号分隔的字符串,
while($row=$result->fetch_array()){
if($rows=='') //this prevents from inserting comma on before the first element
$rows.=$row['email'];
else
$rows.=','.$row['email'];
}
Now you can use
现在你可以使用了
$to = explode(',',$rows); // to change to array
$string =implode(',',$cc); //to get back the string separated by comma
With above code you can send the email like this
使用上面的代码,您可以发送这样的电子邮件
mail($string, "Test", "Hi, Happy X-Mas and New Year");
#8
1
In mail function you can as many reciepient as you want in $emailto paramater seperated by comma.
在邮件功能中,您可以使用逗号分隔的$ emailto paramater中尽可能多的reciepient。
#9
1
It is very bad practice to send all email addresses to all recipients; you should use Bcc (blind carbon copies).
将所有电子邮件地址发送给所有收件人是非常糟糕的做法;你应该使用密送(盲目复印件)。
$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
#10
0
I think the following code will works.
我认为以下代码将有效。
$tos = array('address1@yourdomain.com', 'address2@yourdomain.com');
foreach ($tos as $to){
$ok = mail ($to, $subject, $body, $from);
}
if ($ok) {
echo "Message Send";
} else {
echo "Error";
}
#11
0
Try this. It works for me.
尝试这个。这个对我有用。
$to = $email1 .','. $email2 .','. $email3;
#12
-2
Programmatically sending an submitted form to multiple email address is a possible thing, however the best practice for this is by creating a mailing list. On the code the list address will be place and any change or update on email addresses to the recipients list can be done without changing in the code.
以编程方式将提交的表单发送到多个电子邮件地址是可能的,但最好的做法是创建一个邮件列表。在代码上将放置列表地址,并且可以在不更改代码的情况下完成对收件人列表的电子邮件地址的任何更改或更新。