php - How to set up these email headers with Mailgun API -
i'm using curl php communicate mailgun api. have 2 emails need recipients receive email next headers. give me illustration code snippet in curl (or curl library php) accomplish these mail service headers?
-- email 1 --
from: "my name" content-type: text/plain;charset="iso-8859-1" content-transfer-encoding: 8bit
-- email 2 --
mime-version: 1.0 from:my.domain.com <customerservice@mydomain.com> reply-to: my.domain.com <customerservice@mydomain.com> content-type: multipart/alternative;boundary="=_730dc78ab764a3e997c2c451d9352d87" message-id: <ndfmzn.jquf15@my.domain.com>
you can add together many headers want within array long they're prefixed "h:" @ line
'h:message-id'=> 'ndfmzn.jquf15@my.domain.com', //your message-id
below larger explanation of how can implement this:
<?php $mg_api = 'key-xxx'; //your api key $mg_version = 'api.mailgun.net/v2/'; //root url mailgun $mg_domain = "samples.mailgun.org"; //your domain specified in command panel $mg_from_email = "info@samples.com"; // email $mg_reply_to_email = "info@samples.org"; // reply-to email (usually matches email) $mg_message_url = "https://".$mg_version.$mg_domain."/messages"; $ch = curl_init(); curl_setopt($ch, curlopt_httpauth, curlauth_basic); curl_setopt ($ch, curlopt_maxredirs, 3); curl_setopt ($ch, curlopt_followlocation, false); curl_setopt ($ch, curlopt_returntransfer, 1); curl_setopt ($ch, curlopt_verbose, 0); curl_setopt ($ch, curlopt_header, 1); curl_setopt ($ch, curlopt_connecttimeout, 10); curl_setopt ($ch, curlopt_ssl_verifypeer, 0); curl_setopt ($ch, curlopt_ssl_verifyhost, 0); curl_setopt($ch, curlopt_userpwd, 'api:' . $mg_api); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_url, $mg_message_url); curl_setopt($ch, curlopt_postfields, array( 'from' => 'you@domain.com', 'to' => 'receiver@receiver.com', 'h:reply-to'=> ' <' . $mg_reply_to_email . '>', 'h:message-id'=> 'ndfmzn.jquf15@my.domain.com', //your message-id 'subject' => 'hello', 'html' => 'mailgun pow pow!' )); $result = curl_exec($ch); curl_close($ch); $res = json_decode($result,true); print_r($res);
php api email curl mailgun
No comments:
Post a Comment