当变量用作值时 Mailgun 不发送电子邮件 PHP

Mailgun not Sending emails when variable is used as value PHP

只要 "to" 值被硬编码,就会发送电子邮件。但是,当字符串值替换为字符串变量时,不会发送电子邮件。

$result = $mgClient->sendMessage($domain, array(
    'from'    => 'Eemayl Ok <mailgun@domain.net>',
    'to'      => $customerEmail,
    'to'      => Tools::safeOutput($customerEmail),
    'to'      => (string)$customerEmail,
    'to'      => $customer->email,
    'to'      => Tools::safeOutput($customer->email),
    'to'      => 'hardcoded_email@gmail.com',
    'subject' => 'We Hope You get this Email!',
    'text'    => '',
    'html'      => '<html>Contact Us Ok??</a></html>'       
));

几个"to"是我对变量值表达方式的尝试

数组不接受重复键。如果键重复,它只会选择最后一个值。根据 mailgun API,您应该使用逗号分隔多个收件人。

$recipients = array('client1@gmail.com', 'client2@gmail.com');
$result = $mgClient->sendMessage($domain, array(
    'from'    => 'Eemayl Ok <mailgun@domain.net>',
    'to'      => implode(',', $recipients),
    'subject' => 'We Hope You get this Email!',
    'text'    => '',
    'html'      => '<html>Contact Us Ok??</a></html>'       
));