【发布时间】:2016-03-14 01:54:39
【问题描述】:
我发现了类似的问题,但我仍然不清楚。 如何使用 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);
}
【问题讨论】:
-
您想如何发送电子邮件?作为多个单独的电子邮件给这些收件人?还是作为一封电子邮件有许多收件人?
-
更快的方法。我认为这是一封有很多收件人的电子邮件。
-
@BenRowe 如果是`多个单独的电子邮件给多个收件人`,我们需要做什么?
-
您需要逐个遍历每个收件人。