Test'; $ch = curl_init(); $senddata = '{ "Messages":[ { "From": { "Email": "ujjwal@sentientgeeks.com", "Name": "Ujjwal" }, "To": [ { "Email":"'.$to.'" } ], "Subject": "'.$subject.'", "HTMLPart": "'.$message.'" } ] }'; //echo $senddata;die; $username='bad29f69421a73e83da553fafda450a2'; $password='8ace947e7398c99ec88b2f9646e1a057'; $headers = array( 'Content-Type:application/json' //'Authorization: Basic YmFkMjlmNjk0MjFhNzNlODNkYTU1M2ZhZmRhNDUwYTI6OGFjZTk0N2U3Mzk4Yzk5ZWM4OGIyZjk2NDZlMWEwNTc=' ); curl_setopt($ch, CURLOPT_URL, "https://api.mailjet.com/v3.1/send"); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$senddata); //curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"cc\":[\"cc@example.net\":\"cc whom!\"],\"text\":\"This is the text\",\"bcc\":[\"ujjwal@sentientgeeks.com\":\"bcc whom!\"],\"replyto\":[\"ujjwal@sentientgeeks.com\",\"reply to!\"],\"html\":\"This is the

HTML

This is inline image 1.
\"image1\"
Some text
This is inline image 2.
\"image2\"
Some more text
Re-used inline image 1.
\"image3\"\",\"to\":{\"ujjwal@sentientgeeks.com\":\"to whom!\"},\"attachment\": {\"myfilename.pdf\":\"your_pdf_files_base64_encoded_chunk_data\"},\"from\":[\"ujjwal@sentientgeeks.com\",\"from email!\"],\"subject\":\"My subject\",\"headers\":{\"Content-Type\":\"text/html; charset=iso-8859-1\", \"X-param1\":\"value1\",\"X-param2\":\"value2\", \"X-Mailin-custom\":\"my custom value\",\"X-Mailin-IP\":\"102.102.1.2\", \"X-Mailin-Tag\":\"My tag\"},\"inline_image\":{\"myinlineimage1.png\":\"your_png_files_base64_encoded_chunk_data\", \"myinlineimage2.jpg\":\"your_jpg_files_base64_encoded_chunk_data\"}}"); curl_setopt($ch, CURLOPT_POST, 1); //$headers = array(); //$headers[] = "user: bad29f69421a73e83da553fafda450a2:8ace947e7398c99ec88b2f9646e1a057"; //$headers[] = "Content-Type: application/json"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close ($ch); print_r($result); // require_once(APPPATH.'sendgrid-php/sendgrid-php.php'); // include APPPATH . 'sendgrid-php/sendgrid-php.php'; // $email = new \SendGrid\Mail\Mail(); /* $email->setFrom("setfrom@test.com", "testname"); $email->setSubject("MailTest"); $email->addTo('tomail@gmail.com', "User"); $email->addContent("text/plain", "subject"); $email->addContent( "text/html",'Message'); $sendgrid = new \SendGrid(('sendgrid-API-KEY_HERE')); try { $response = $sendgrid->send($email); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $e) { echo 'Caught exception: '. $e->getMessage() ."\n"; } /* $CI->load->library('email'); /* $config['protocol'] = 'smtp'; //$config['smtp_host'] = 'smtp.mailtrap.io'; $config['smtp_host'] = 'smtp.sendgrid.net'; $config['smtp_port'] = '587'; $config['smtp_timeout'] = '30'; // $config['smtp_user'] = '505a0d93534180'; // $config['smtp_pass'] = '07433d0ae4879d'; $config['smtp_user'] = 'apikey'; $config['smtp_pass'] = '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'; $config['charset'] = 'utf-8'; $config['newline'] = "\r\n"; $config['mailtype'] = 'html'; // or html $config['validation'] = TRUE; // bool whether to validate email or not $CI->email->initialize(array( 'protocol' => 'smtp', 'smtp_host' => 'smtp-relay.sendinblue.com', 'smtp_user' => 'ujjwal@sentientgeeks.com', 'smtp_pass' => '4zT95dpUAYCNLnEO', 'smtp_port' => 587, 'crlf' => "\r\n", 'newline' => "\r\n" )); //$CI->email->initialize($config); //$CI->load->library('email'); $CI->email->from($from['email'],$from['name']); $CI->email->to($to); $CI->email->subject($subject); $CI->email->message($message); $CI->email->send(); echo $CI->email->print_debugger(); */ } function cgq_email($to,$subject,$message) { $msg= "this is test mail"; $message = $msg; // echo $message; // die(); $CI = &get_instance(); $ch = curl_init(); $senddata = '{ "Messages":[ { "From": { "Email": "ujjwal@sentientgeeks.com", "Name": "Ujjwal" }, "To": [ { "Email":"'.$to.'" } ], "Subject": "'.$subject.'", "HTMLPart": "'.$message.'" } ] }'; $username='bad29f69421a73e83da553fafda450a2'; $password='8ace947e7398c99ec88b2f9646e1a057'; $headers = array( 'Content-Type:application/json' //'Authorization: Basic YmFkMjlmNjk0MjFhNzNlODNkYTU1M2ZhZmRhNDUwYTI6OGFjZTk0N2U3Mzk4Yzk5ZWM4OGIyZjk2NDZlMWEwNTc=' ); curl_setopt($ch, CURLOPT_URL, "https://api.mailjet.com/v3.1/send"); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$senddata); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close ($ch); print_r($result); } ?>