我需要向多个收件人发送电子邮件。收件人的数量将根据数据库中的数据而有所不同。
Mandrill 允许我只使用数组添加多个收件人。
以下是适用于多个收件人的内容
//email array that needs to be added to the 'to' key
$emailArray = ["example@example.com","test@test.com","hello@test.com","world@test.com"];
$mandrill = new Mandrill('xxxxxxxxxxxxxxx');
$message = array(
'subject' => 'Thanks for signing up',
'from_email' => 'support@test.com',
'to' => array(
array(
'email' => 'hello@test.com',
'name' => 'Hello Test'
),
array(
'email' => 'goodbye@test.com',
'name' => 'Goodbye Test',
)
),
'global_merge_vars' => array(
array(
'name' => 'FIRSTNAME',
'content' => 'JOHN'
),
array(
'name' => 'LASTNAME',
'content' => 'DOE')
));
//print_r($message);
$template_name = 'hello-world';
print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));
下面是我需要根据 emailArray 的长度动态生成的内容
to' => array(
//the below array should be dynamically generated
array(
'email' => 'hello@test.com',
'name' => 'Hello Test'
),
array(
'email' => 'goodbye@test.com',
'name' => 'Goodbye Test',
)
)
这是数组。目前具有固定值。
//email array that needs to be added to the 'to' key
$emailArray = ["example@example.com","test@test.com","hello@test.com","world@test.com"];
我的问题是如何根据电子邮件数组的长度生成“收件人”值?
有没有办法让整个数组脚本内爆?