Search
 
SCRIPT & CODE EXAMPLE
 

PHP

mailjet

<?php


namespace WebBundleService;
 
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;

class Mailjet
{

    private $apiKey = "yourKey";
    private $mailjetApiSecret = "mailjetApiSecret" ;
    private $message  ;
    private $emails ;
    private $sujet ;
    private $from ;
    private $fromName ;
    private $to ;


    public function __construct( $message , $sujet , $from ,  $fromName , $to , $emails  )
    {
        $this->message = $message;
        $this->emails = $emails;
        $this->sujet = $sujet;
        $this->fromName = $fromName;
        $this->from = $from;
        $this->to = $to;
    }

    public function send (){

        $messageData = array(
            'Messages' => array(
                array(
                    'From' => array(
                        'Email' => $this->from,
                        'Name' => $this->fromName
                    ),
                    'To' => array(
                        array(
                            'Email' => $this->emails,
                            'Name' => $this->to
                        )
                    ),
                    'Subject' => $this->sujet,
                    'HTMLPart' => $this->message
                )
            )
        );

        $jsonData = json_encode($messageData);
        $ch = curl_init('https://api.mailjet.com/v3.1/send');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
        curl_setopt($ch, CURLOPT_USERPWD, "{$this->apiKey}:{$this->mailjetApiSecret}");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'Content-Length: ' . strlen($jsonData)
        ]);
        $response = json_decode(curl_exec($ch));

        return$response  ;
    }








}

// how to use in your code 

//  public function sendEmail(Request $request )
//    {

//        $test = new Mailjet("Your message","Subject","youremail@host.com",'your name',"you client name", "clientEmail@host.com" );

//        $result = $test->send();

 //       dump( $result);die();
//    }
    
    
Comment

PREVIOUS NEXT
Code Example
Php :: whats the difference between using date function and DATETime in php 
Php :: php backend generator 
Php :: how to lookup value inside object php 
Php :: if else php 
Php :: convert html to pdf php 
Php :: run cron job in seconds 
Php :: What’s New in PHP 8 
Php :: error handling in laravel 
Php :: phpdoc example 
Php :: laravel property 
Php :: laravel set middleware default 
Php :: cron job setting for laravel in cpanel 
Php :: php mvc example 
Php :: auto logout when session expires laravel 
Php :: laravel admin disable batch selection 
Php :: #FF0000; 
Php :: put_assoc 
Php :: php enc 
Php :: laravel This package is not auto-updated. Please set up the GitHub Hook for Packagist so that it gets updated whenever you push! 
Php :: wordpress page template comment 
Php :: how to alter table stracture in sql using php 
Php :: get server name php 
Php :: extract email from text 
Php :: Validate checkboxes laravel 
Php :: php jwt firebase 
Php :: wp rest api remove _links 
Php :: php mysql insert record if not exists in table 
Php :: To fetch the soft deleted user, you should use withTrashed 
Php :: small echo php 
Php :: convert array to associative array php 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =