ihaveitnow
ihaveitnow

Reputation: 113

Mailgun not Sending emails when variable is used as value PHP

Whenever the "to" value is hardcoded, the email is sent. However, when the string value is replaced with a string variable the email does not get sent.

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

The several "to"s are my attempt at variations of expressing the variable value.

Upvotes: 0

Views: 416

Answers (1)

Ben
Ben

Reputation: 5129

Array does not accept duplicate keys. It only chooses the last value if key duplicated. According to mailgun API, You should use commas to separate multiple recipients.

$recipients = array('[email protected]', '[email protected]');
$result = $mgClient->sendMessage($domain, array(
    'from'    => 'Eemayl Ok <[email protected]>',
    'to'      => implode(',', $recipients),
    'subject' => 'We Hope You get this Email!',
    'text'    => '',
    'html'      => '<html>Contact Us Ok??</a></html>'       
));

Upvotes: 1

Related Questions