PHP邮件:多个收件人? [英] PHP mail: Multiple recipients?

查看:110
本文介绍了PHP邮件:多个收件人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

 <?php 
include(db.php);

$ result = mysql_query(SELECT * FROM email);

while($ row = mysql_fetch_array($ result))
{
$ to = $ row ['address'];
}
$ subject =测试邮件;
$ message =你好!这是一个简单的电子邮件。
$ from =example@example.com;
$ headers =From:。从$;
mail($ to,$ subject,$ message,$ headers);
?>

在我的表(电子邮件)中我有多个地址。
(它们不是逗号分隔)
我可以如何发送我的消息到所有这些地址?

解决方案

$($ row = mysql_fetch_array($ result))
{
$ addresses [] = $ row ['address'];
}
$ to = implode(,,$ addresses);

mail()手册页,函数的to参数可以采用逗号分隔的列表的地址。


I have this code:

<?php
include("db.php");

$result = mysql_query("SELECT * FROM email");

while($row = mysql_fetch_array($result))
{
$to = $row['address'];
}
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "example@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>

In my table ("email") I have multiple addresses. (They are not comma sepparated.) How could I send my message to all of those addresses?

解决方案

while($row = mysql_fetch_array($result))
{
    $addresses[] = $row['address'];
}
$to = implode(", ", $addresses);

As specified on the mail() manual page, the "to" parameter of the function can take a comma-separated list of addresses.

这篇关于PHP邮件:多个收件人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆