Nith
Nith

Reputation: 742

Mail gun Cc header issue

Am using this function to sent bulk mail through mail gun

`//sending batch mail public function BatchMail($subject=null,$body=null, $record=null) { # Instantiate the client. $mg = new Mailgun(MAILGUN_KEY); $domain = MAILGUN_DOMAIN;

    # Next, instantiate a Message Builder object from the SDK, pass in your sending domain
    if(!empty($record))
    {
        $batchMsg = $mg->BatchMessage($domain);

        # Define the from address.
        $batchMsg->setFromAddress(FROM_EMAIL, array("first"=>FIRST_NAME, "last" => LAST_NAME));

        # Define the subject. 
        $batchMsg->setSubject($subject);

        # Define the body of the message.
        $batchMsg->setHtmlBody($body);

        # Next, let's add a few recipients to the batch job.
        foreach ($record as $key => $rec) {

            $batchMsg->addToRecipient($rec['email'], array("first" => $rec['fname'], "last" => $rec['lname']));
        }
        $batchMsg->addCcRecipient("[email protected]", array("first" => "Sally", "last" => "Doe"));

        $re     = $batchMsg->finalize();
        $result = $batchMsg->getMessage();

        $log    = $mg->get("$domain/log");
        $respbody = $log->http_response_body;
        $result = $mg->get("$domain/stats",array('event' => array('sent', 'opened')));
        $resp   = $log->http_response_code;
        //$event  = $mg->get("$domain/events");
        $response = array("log"=>$log,"result"=>$result,"body"=>$respbody,"code"=>$resp);
        return  $response;
    }   
}`

Here mails are sending properly but I have a problem in my cc mail.

$batchMsg->addCcRecipient("[email protected]", array("first" => "Sally", "last" => "Doe"));

This function using for adding CC mails. Mails are delivering properly but the mail reviving with headers like To: [email protected], Cc:[email protected]. But the recipients mails are not listing in the headers.

Normally gamil showing recipients in the headers like this to: [email protected] cc: [email protected]

Anyone know why mail gun showing issue like this ??

Upvotes: 4

Views: 1041

Answers (1)

jarederaj
jarederaj

Reputation: 1390

Replace:

   foreach ($record as $key => $rec) {
       $batchMsg->addToRecipient($rec['email'], array("first" => $rec['fname'], "last" => $rec['lname']));
   }

With:

   foreach ($record as $key => $rec) {
       $batchMsg->addBccRecipient($rec['email'], array("first" => $rec['fname'], "last" => $rec['lname']));
   }

Or if you want your recipients to know who else was emailed don't use the batch message builder. See the "To" parameter in the mailgun API documentation for proper formatting.

The batch builder is for sending many distinct emails and not for composing a single email to many different recipients. It's possible that MailGun didn't anticipate you building an email to multiple recipients this way and thus there is no test coverage of this bug. You might try filing a bug report on their github page.

More details about the specification you're trying to implement might lead to a better answer.

Upvotes: 0

Related Questions