社区首页 >问答首页 >如何使用php发送2封以上的邮件?

如何使用php发送2封以上的邮件?
EN

Stack Overflow用户
提问于 2013-03-14 07:30:25
回答 5查看 430关注 0票数 0

我想同时为两个不同的用户发送两封电子邮件。我使用的是php邮件功能。下面是代码。

代码语言:javascript
代码运行次数:0
复制
 Send_Mail('abc@example.com,abc2@example.com','Welcome',$message);

当我将它发送给单个用户时,它工作fine.But当我添加两个邮件地址它不工作..有没有其他方法可以解决这个问题?帮帮我,朋友们..

提前谢谢..

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-03-14 07:38:44

如果您将电子邮件发送到多个地址,则可能需要在邮件头中指定收件人。

代码语言:javascript
代码运行次数:0
复制
$to = 'abc@example.com' . ', ' . 'abc2@example.com';
$subject = 'Welcome';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: ' . $to . "\r\n";
//$headers .= 'From: Someone <someone@example.com>' . "\r\n";
//$headers .= 'Cc: otherperson@example.com' . "\r\n";
//$headers .= 'Bcc: theotherperson@example.com' . "\r\n";

Send_Mail($to, $subject, $message, $headers);
票数 0
EN

Stack Overflow用户

发布于 2013-03-14 07:36:59

试试这个:

代码语言:javascript
代码运行次数:0
复制
$recipients = array('abc@example.com','abc2@example.com');
foreach ($recipients as $to) {
    Send_Mail($to,'Welcome',$message);
}

代码语言:javascript
代码运行次数:0
复制
$to = 'abc@example.com,abc2@example.com';
Send_Mail($to,'Welcome',$message);
票数 2
EN

Stack Overflow用户

发布于 2013-03-14 07:33:58

代码语言:javascript
代码运行次数:0
复制
$emailArray = array ('abc@example.com','abc2@example.com');
for($i=0;$i<count($emailArray);$i++)
{
Send_Mail($emailArray[$i],'Welcome',$message);
}

现在,您可以在阵列数据上发送无限的emails...based

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15403516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文