src/Controller/CRUD/BaseCRUDController.php line 7

Open in your IDE?
  1. <?php
  2. namespace App\Controller\CRUD;
  3. use Sonata\AdminBundle\Controller\CRUDController;
  4. class BaseCRUDController extends CRUDController
  5. {
  6.     public function enviaEmailClienteAction($email$file$assunto$descricao$nome_arquivo) {
  7.     //public function enviaEmailClienteAction(Request $request) {
  8.         // $email = 'brunofredericot@gmail.com';
  9.         
  10.         // $api_key = '688e8542d65f5987daaab6242b81349d-5e3f36f5-6b0a3dac';
  11.         // $domain_name = 'sandbox4489fe390ff647f89401930718118696.mailgun.org';
  12.         
  13.         // $url = "https://api.mailgun.net/v3/{$domain_name}/messages";
  14.         
  15.         // $data = [
  16.         //     'from' => 'Excited User <mailgun@' . $domain_name . '>',
  17.         //     //'to' => 'YOU@' . $domain_name,
  18.         //     'to' => $email,
  19.         //     'subject' => 'Hello',
  20.         //     'text' => 'Testing some Mailgun awesomeness!'
  21.         // ];
  22.         
  23.         // $ch = curl_init($url);
  24.         
  25.         // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  26.         // curl_setopt($ch, CURLOPT_USERPWD, "api:$api_key");
  27.         // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  28.         // curl_setopt($ch, CURLOPT_POST, 1);
  29.         // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  30.         
  31.         // $response = curl_exec($ch);
  32.         
  33.         // var_dump($response);
  34.         
  35.         // curl_close($ch);
  36.         $ch curl_init();
  37.         
  38.         //$email =  "brunofredericot@gmail.com";
  39.         
  40.         // $file =  "/www/wwwroot/gestor.ltec.eng.br/documentos_temporarios_para_email/proposta_1670025321.pdf";
  41.         // $assunto =  "Teste";
  42.         // $descricao =  "<p style='text-align:center;'><img src='https://gestor.ltec.eng.br/media/images/logo.png' style='width:300px;'><p>
  43.         // <h2 style='text-align:center;'>Este é um e-mail automático enviado pelo sistema de gestão LTEC e contém um documento em anexo.</h2>";
  44.         // $nome_arquivo = "Teste";
  45.         $file_encoded base64_encode(file_get_contents($file));
  46.         $payload '{"personalizations": [{"to": [{"email": "'.$email.'"}]}],"from": {"email": "contato@ltec.eng.br"},"subject": "'.$assunto.'","content": [{"type": "text/html", "value": "'.$descricao.'"}], "attachments":[{"content": "'.$file_encoded.'", "type": "application/pdf", "filename": "'.$nome_arquivo.'.pdf"}]}';
  47.                 
  48.         curl_setopt($chCURLOPT_URL'https://api.sendgrid.com/v3/mail/send');
  49.         curl_setopt($chCURLOPT_RETURNTRANSFER1);
  50.         curl_setopt($chCURLOPT_POST1);
  51.         curl_setopt($chCURLOPT_POSTFIELDS$payload);
  52.         
  53.         $headers = array();
  54.         //$headers[] = 'Authorization: Bearer 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';
  55.         $headers[] = 'Authorization: Bearer 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';
  56.         $headers[] = 'Content-Type: application/json';
  57.         curl_setopt($chCURLOPT_HTTPHEADER$headers);
  58.         
  59.         $result curl_exec($ch);
  60.         if (curl_errno($ch)) {
  61.             echo 'Error:' curl_error($ch);
  62.         }
  63.         
  64.         curl_close($ch);
  65.         
  66.         $responseJson json_decode($result);
  67.         
  68.         print_r($responseJson);
  69.         exit;
  70.         
  71.         if( property_exists($responseJson"errors") ){
  72.             return false;
  73.         }
  74.         return true;
  75.     }
  76. }