src/Service/Mailjet.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use Mailjet\Client;
  4. use Mailjet\Resources;
  5. class Mailjet
  6. {
  7.     private $api_key "83fdc7c5f9e50a3dd7b8fc554805fdc8";
  8.     private $api_secret "b43ff1b0323954b73575f5a62f7968c6";
  9.     public function send($from_email$from_name$to_email$to_name$subject$content$contract false$booking false$tpl_id)
  10.     {
  11.         $mj = new Client($this->api_key$this->api_secrettrue, ['version' => 'v3.1']);
  12.         if ($contract != false && $booking != false) {
  13.             $body = [
  14.                 'Messages' => [
  15.                     [
  16.                         'From' => [
  17.                             'Email' => $from_email,
  18.                             'Name' => $from_name
  19.                         ],
  20.                         'To' => [
  21.                             [
  22.                                 'Email' => $to_email,
  23.                                 'Name' => $to_name
  24.                             ]
  25.                         ],
  26.                         'TemplateID' => $tpl_id,
  27.                         'TemplateLanguage' => true,
  28.                         'Subject' => $subject,
  29.                         'Variables' => [
  30.                             'content' => $content,
  31.                         ],
  32.                         'Attachments' => [
  33.                             [
  34.                                 'ContentType' => "application/pdf",
  35.                                 'Filename' => "contrat-de-location-saisonniere.pdf",
  36.                                 'Base64Content' => $contract
  37.                             ]
  38.                         ]
  39.                     ]
  40.                 ]
  41.             ];
  42.         } else {
  43.             $body = [
  44.                 'Messages' => [
  45.                     [
  46.                         'From' => [
  47.                             'Email' => $from_email,
  48.                             'Name' => $from_name
  49.                         ],
  50.                         'To' => [
  51.                             [
  52.                                 'Email' => $to_email,
  53.                                 'Name' => $to_name
  54.                             ]
  55.                         ],
  56.                         'TemplateID' => $tpl_id,
  57.                         'TemplateLanguage' => true,
  58.                         'Subject' => $subject,
  59.                         'Variables' => [
  60.                             'content' => $content,
  61.                         ]
  62.                     ]
  63.                 ]
  64.             ];
  65.         }
  66.         $response $mj->post(Resources::$Email, ['body' => $body]);
  67.         $response->success();
  68.     }
  69. }