php - How to send email through MailChimp 3.0 api? -
i'm trying send email through mailchimp api version 3.0 in php, have no luck. code:
$poststring = '{ "message": { "html": "this emails html content", "text": "this emails text content", "subject": "this subject", "from_email": "xxx@dyyy.sk", "from_name": "john", "to_email": "aaa.bbb@gmail.com", "to_name": "anton", "track_opens": false, "track_clicks": false }}'; $ch = curl_init(); curl_setopt($ch, curlopt_url, $this->api_endpoint); curl_setopt($ch, curlopt_httpauth, curlauth_basic); curl_setopt($ch, curlopt_userpwd, 'drewm:'.$this->api_key); curl_setopt($ch, curlopt_httpheader, array('accept: application/vnd.api+json', 'content-type: application/vnd.api+json')); curl_setopt($ch, curlopt_useragent, 'drewm/mailchimp-api/3.0 (github.com/drewm/mailchimp-api)'); curl_setopt($ch, curlopt_followlocation, true ); curl_setopt($ch, curlopt_returntransfer, true ); curl_setopt($ch, curlopt_timeout, $timeout); curl_setopt($ch, curlopt_ssl_verifypeer, $this->verify_ssl); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $poststring); curl_setopt($ch, curlopt_http_version, curl_http_version_1_0); $result = curl_exec($ch); echo $result;
what doing wrong?
my code here worked test mail, it's same thing non test, url changing.
<?php $apikey = "your api key found in account"; $campaignid = "your campaign id, need create one. use playground id"; $memberid = md5(strtolower("membermail")); $datacenter = substr($apikey,strpos($apikey,'-')+1); $url = 'https://'. $datacenter . '.api.mailchimp.com/3.0/campaigns/' . $campaignid .'/actions/test'; $jsonemail = '{"test_emails":["the mail want send thing sat"],"send_type":"html"}'; $ch = curl_init($url); curl_setopt($ch, curlopt_userpwd, 'apikey:'.$apikey); curl_setopt($ch, curlopt_httpheader, ['content-type: application/json']); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_timeout, 10); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $jsonemail); $result = curl_exec($ch); curl_close($ch); var_dump($result); ?>
you should have string "0" if went well. wait bit , mail sent.
good luck !
Comments
Post a Comment