Sukesh
Sukesh

Reputation: 194

How to send Summer note content directly via email

I need to send a mail with the summer note content,I'm using Code Igniter loadview method to render body of my mail but text content displaying images are not

Once i got the issue "transfer closed, bytes remaining to read" I jhave fixed this issue using this link

https://justrocketscience.com/post/php_guzzle_bug/

newsletterMail.php

<html>
<head>Mailer</head>
<?php echo $body; ?>
</html>



$view= $this->CI->load>view('admin_user/newsletterMail',$pageData,TRUE);    

$headers=array(
            'Authorization: Bearer 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',
            'Content-Type: application/json'
        );

        $data=[
            "personalizations"=>[
                [
                    "to"=>$mailData['to']
                ]
            ],
            "from"=>[
                "email"=>"[email protected]"
            ],
            "subject"=>$subject,
            "content"=>[
                [
                    "type"=>"text/html",
                    "value"=>$body
                ]
            ]
        ];

$ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,"https://api.sendgrid.com/v3/mail/send");
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($data));
        curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_TCP_KEEPALIVE, 10);
        curl_setopt($ch,CURLOPT_TCP_KEEPIDLE, 10);
        $response= curl_exec($ch);
        $err = curl_error($ch);
        curl_close($ch);

I need to show the content which I created in summer note in mail

Any solution?

Upvotes: 0

Views: 979

Answers (1)

Jayesh
Jayesh

Reputation: 161

Instead of using curl you can use default email functionality of codeigniter to send mail, also use SMTP protocol to send mail. Check below code to send mail.

function setProtocol(){
   $CI = &get_instance();

   $CI->load->library('email');

   $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'smtp.googlemail.com',
      'smtp_port' => 465, //(Port: 465 (SSL required) or 587 (TLS required))
      'smtp_user' => '**************', //(your Gmail account (e.g. [email protected]))
      'smtp_pass' => '**************', //(your Gmail password)
      'mailtype' => "html",
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE,
      'newline' => '\r\n',
    );

    $CI->email->initialize($config);

    return $CI;
 }

function newsletter(){
  $CI = setProtocol();        

  $CI->email->from('[email protected]');
  $CI->email->subject("Enter your subject");
  $CI->email->message($CI->load->view('admin_user/newsletterMail', $pageData, TRUE));
  $CI->email->to('[email protected]');
  $status = $CI->email->send();

  return $status;
}

You can use setProtocol() globally to send other emails also.

Upvotes: 0

Related Questions