How to integrate dyn email api in laravel,dyn email delivery, dyn email api, dyn email service,dyn email api, integrate dyn email api, integrate dyn email api in laravel

How to integrate dyn email api in laravel

In this tutorial, We are going to integrate DYN Email API into a Laravel application. The DYN email API allows us to send emails from our website. DYN Email Delivery provides a REST API to allow for programmatic access to the system. We can configure our account via the API, request reporting data, Check email status, update recipient status, Retrieve metrics from your Dyn Delivery accounts, and most other functions available within the user interface. DYN Email Delivery provides the followings API’s to integrate into Laravel:-

SEND EMAIL

TO send an email with DYN API you need to pass the following parameters:-

APIKEY

from

to

subject

Now send a post request using php CURL


 "https://emailapi.dynect.net/rest/json/send",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "apikey='YOUR API KEY'&from='ENTER FROM'&to='RECIPIENT EMAIl ID'&subject='YOUR SUBJECT'&bodytext='BODY TEXT HERE'",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/x-www-form-urlencoded"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

CHECK DELIVERED EMAILS

To check how much emails are delivered, you have to pass the following parameters using GET request:-

apikey

STARTTIME

ENDTIME

Check below example code:-

$strDate= date('Y-m-d h:i:s');
    $url = "https://emailapi.dynect.net/rest/json/reports/delivered";
    $startdate = date('Y-m-d');
    $enddate = date('Y-m-d', strtotime(' +1 day'));
    //$api_key = "YOUR API KEY";
    $curl = curl_init();
    $successArray=array();


    curl_setopt_array($curl, array(
      CURLOPT_URL => $url."?apikey=".$this->api_key."&starttime=".$startdate."&endtime=".$enddate,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {

      $resultData=json_decode($response);
      //pr($resultData); die;

CHECK BOUNCED EMAILS

To check how much emails are BOUNCED, you have to pass the following parameters using GET request:-

APIKEY

STARTTIME

ENDTIME

Check below example code:-

$strDate= date('Y-m-d h:i:s');
    $url = "https://emailapi.dynect.net/rest/json/reports/bounced";
    $startdate = date('Y-m-d');
    $enddate = date('Y-m-d', strtotime(' +1 day'));
    //$api_key = "YOUR API KEY";
    $curl = curl_init();
    $successArray=array();


    curl_setopt_array($curl, array(
      CURLOPT_URL => $url."?apikey=".$this->api_key."&starttime=".$startdate."&endtime=".$enddate,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {

      $resultData=json_decode($response);

After send the GET request for bounced email you will recieve like below response from DYN EMAIL:-



{
    "response": {
        "status": 200,
        "message": "OK",
        "data": {
            "bounces": [
                {
                    "emailaddress": "email@example.com",
                    "bouncetype": "soft",
                    "bouncerule": "no-answer-from-host",
                    "bouncecode": "4.4.1",
                    "bouncetime": "2019-12-01T04:33:16+00:00",
                    "notified": false,
                    "notifiedtime": 0,
                    "X-campaign": null,
                    "X-country": null,
                    "xheaders": {
                        "X-campaign": null,
                        "X-country": null
                    }
                }
             ]
        }
    }


CHECK BLOCKED EMAILS AND THEIR REASONS

To check how much emails are BLOCKED, you need to pass the following parameters using GET request:- APIKEY STARTTIME ENDTIME Check below example code:-
$strDate= date('Y-m-d h:i:s');
    $url = "https://emailapi.dynect.net/rest/json/reports/blockedemail";
    $startdate = date('Y-m-d');
    $enddate = date('Y-m-d', strtotime(' +1 day'));
    //$api_key = "YOUR API KEY";
    $curl = curl_init();
    $successArray=array();


    curl_setopt_array($curl, array(
      CURLOPT_URL => $url."?apikey=".$this->api_key."&starttime=".$startdate."&endtime=".$enddate,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {

      $resultData=json_decode($response);

After sending the GET request for blocked email you will receive like below response from DYN EMAIL:-



{
    "response": {
        "status": 200,
        "message": "OK",
        "data": {
            "blocked-email": [
                {
                    "userid": 475998,
                    "senttime": "2019-11-09T19:56:53+00:00",
                    "date": "2019-11-09T19:56:53+00:00",
                    "emailaddress": "abc@gmail.com",
                    "email": "abc@gmail.com",
                    "blockedreason": "hardbounce",
                    "xheaders": {
                        "X-campaign": null,
                        "X-country": null
                    }
                }
             ]
        }
    }    

DYN email more rest API'S to check email status. You need to go DYN email official website. If you have any question please comment below.

How to integrate dyn email api in laravel,dyn email delivery, dyn email api, dyn email service,dyn email api, integrate dyn email api, integrate dyn email api in laravel

Post Created 120

Leave a Reply

Related Posts

Begin typing your search above and press enter to search. Press ESC to cancel.

Back To Top