Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Mandrill API向多个收件人发送电子邮件?_Php_Mandrill - Fatal编程技术网

Php 如何使用Mandrill API向多个收件人发送电子邮件?

Php 如何使用Mandrill API向多个收件人发送电子邮件?,php,mandrill,Php,Mandrill,我发现了类似的问题,但我仍然不清楚。 如何使用Mandrill API向多个收件人发送电子邮件 接收人的数量可能因数据库中存储的信息而异: $query = "SELECT emails FROM emails_table"; $data = mysql_query($query); $n = 0; while ($row = mysql_fetch_assoc($data)) { $email[$n] = $row['emails']; $n++; } 因此,电子邮件将存储在这样的变量中。例

我发现了类似的问题,但我仍然不清楚。 如何使用Mandrill API向多个收件人发送电子邮件

接收人的数量可能因数据库中存储的信息而异:

$query = "SELECT emails FROM emails_table";
$data = mysql_query($query);
$n = 0;
while ($row = mysql_fetch_assoc($data))
{
$email[$n] = $row['emails'];
$n++;
}
因此,电子邮件将存储在这样的变量中。例如

$email[0] = email_0@example.com;
$email[1] = email_1@example.com;
$email[2] = email_2@example.com;
这是Mandrill API:

require("/mandrill_mail/src/Mandrill.php");

try {
    $mandrill = new Mandrill('kWre_48F1lnJs3_39YM434z');//API KEY
    $message = array(
        'html' => 'message',
        'subject' => 'subject',
        'from_email' => 'my_mail@my_domain.com',
        'from_name' => 'My_Domain',
        'to' => array(
            array(
                'email' => $email[0], //How can I add the other emails considering that the number of recipients will vary depending on the data in the db?
                'name' => 'Recipient Name',
                'type' => 'to'*/
            )
        ),
        'headers' => array('Reply-To' => 'my_mail@my_domain.com'),
        'important' => false,
        'track_opens' => null,
        'track_clicks' => null,
        'auto_text' => null,
        'auto_html' => null,
        'inline_css' => null,
        'url_strip_qs' => null,
        'preserve_recipients' => false,
        'view_content_link' => null,
        'bcc_address' => $mail_bc,
        'tracking_domain' => null,
        'signing_domain' => null,
        'return_path_domain' => null,
        'merge' => true,
        'merge_language' => 'mailchimp',

    );
    $async = false;
    $ip_pool = 'Main Pool';

    $result = $mandrill->messages->send($message, $async, $ip_pool);
} 
然后


一种简单的方法是通过$emails数组循环并动态地将电子邮件发送到每个电子邮件地址

foreach($emails as $email){

try {
    $mandrill = new Mandrill('kWre_48F1lnJs3_39YM434z');//API KEY
    $message = array(
        'html' => 'message',
        'subject' => 'subject',
        'from_email' => 'my_mail@my_domain.com',
        'from_name' => 'My_Domain',
        'to' => array(
            array(
                'email' => $email, 
                'name' => 'Recipient Name',
                'type' => 'to'*/
            )
        ),
        'headers' => array('Reply-To' => 'my_mail@my_domain.com'),
        'important' => false,
        'track_opens' => null,
        'track_clicks' => null,
        'auto_text' => null,
        'auto_html' => null,
        'inline_css' => null,
        'url_strip_qs' => null,
        'preserve_recipients' => false,
        'view_content_link' => null,
        'bcc_address' => $mail_bc,
        'tracking_domain' => null,
        'signing_domain' => null,
        'return_path_domain' => null,
        'merge' => true,
        'merge_language' => 'mailchimp',

    );
    $async = false;
    $ip_pool = 'Main Pool';

    $result = $mandrill->messages->send($message, $async, $ip_pool);
} 

}
您也可以使用模板通过Mandrill发送新消息。不过,请确保您了解它的限制

对于SMTP邮件,一次最多可以发送1000个收件人。如果要发送给更多收件人,则允许同时和后续连接

对于API,没有收件人限制,但每个API调用提供的JSON必须小于10MB。我们强烈建议较小的收件人批次,以便于故障排除

对于SMTP邮件,一次最多可以发送1000个收件人。 如果要发送给更多收件人,请同时发送和后续发送 允许连接

对于API,没有收件人限制,但是提供了JSON 每个API调用必须小于10MB。我们强烈推荐更小的 收件人批处理以便于故障排除


您想如何发送电子邮件?作为发送给这些收件人的多封单独的电子邮件?或者作为一封包含多个收件人的电子邮件?更快的方式。我认为这是一封有很多收件人的电子邮件。@BenRowe如果是“给多个收件人的多封单独的电子邮件”,我们需要做什么?您需要逐个遍历每个收件人。您确定这种方法吗?api文档说它需要一个收件人的信息在“to”字段中是的,我肯定。本文档指的是在
收件人
字段的
电子邮件
部分中有多个电子邮件地址。
require("/mandrill_mail/src/Mandrill.php");

try {
    $mandrill = new Mandrill('kWre_48F1lnJs3_39YM434z');//API KEY
    $message = array(
        'html' => 'message',
        'subject' => 'subject',
        'from_email' => 'my_mail@my_domain.com',
        'from_name' => 'My_Domain',
        'to' => $emails,
        'headers' => array('Reply-To' => 'my_mail@my_domain.com'),
        'important' => false,
        'track_opens' => null,
        'track_clicks' => null,
        'auto_text' => null,
        'auto_html' => null,
        'inline_css' => null,
        'url_strip_qs' => null,
        'preserve_recipients' => false,
        'view_content_link' => null,
        'bcc_address' => $mail_bc,
        'tracking_domain' => null,
        'signing_domain' => null,
        'return_path_domain' => null,
        'merge' => true,
        'merge_language' => 'mailchimp',

    );
    $async = false;
    $ip_pool = 'Main Pool';

    $result = $mandrill->messages->send($message, $async, $ip_pool);
} 
foreach($emails as $email){

try {
    $mandrill = new Mandrill('kWre_48F1lnJs3_39YM434z');//API KEY
    $message = array(
        'html' => 'message',
        'subject' => 'subject',
        'from_email' => 'my_mail@my_domain.com',
        'from_name' => 'My_Domain',
        'to' => array(
            array(
                'email' => $email, 
                'name' => 'Recipient Name',
                'type' => 'to'*/
            )
        ),
        'headers' => array('Reply-To' => 'my_mail@my_domain.com'),
        'important' => false,
        'track_opens' => null,
        'track_clicks' => null,
        'auto_text' => null,
        'auto_html' => null,
        'inline_css' => null,
        'url_strip_qs' => null,
        'preserve_recipients' => false,
        'view_content_link' => null,
        'bcc_address' => $mail_bc,
        'tracking_domain' => null,
        'signing_domain' => null,
        'return_path_domain' => null,
        'merge' => true,
        'merge_language' => 'mailchimp',

    );
    $async = false;
    $ip_pool = 'Main Pool';

    $result = $mandrill->messages->send($message, $async, $ip_pool);
} 

}