I am trying to send mail through sendgrid API but what i see unusual is its giving me two response codes instead of one. And it does not send mail. Why??
array(16) {
[0]=>
string(22) "HTTP/1.1 100 Continue"
[1]=>
string(1) ""
[2]=>
string(25) "HTTP/1.1 400 Bad Request"
[3]=>
string(14) "Server: nginx"
[4]=>
string(36) "Date: Sun, 12 Mar 2017 22:08:03 GMT"
[5]=>
string(31) "Content-Type: application/json"
[6]=>
string(20) "Content-Length: 507"
[7]=>
string(23) "Connection: keep-alive"
[8]=>
string(22) "X-Frame-Options: DENY"
[9]=>
string(58) "Access-Control-Allow-Origin: https://sendgrid.api-docs.io"
[10]=>
string(35) "Access-Control-Allow-Methods: POST"
[11]=>
string(87) "Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl"
[12]=>
string(28) "Access-Control-Max-Age: 600"
[13]=>
string(75) "X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html"
[14]=>
string(1) ""
[15]=>
string(0) ""
}
I have downloaded the sendgrid code and wrote a wrapper class Mailer
to use sendgrid
I am trying to achieve like this.
$template = APP_PATH."/application/views/layouts/mails/NewEmployee.html";
$mail_body = file_get_contents($template);
$formated_mail_body = str_replace(
["{{name}}", "{{email}}", "{{password}}"], [$name, $email, $password], $mail_body);
$from = [
"name" => "XYZ company",
"email" => "hr@xyz.com"
];
$to = [
["name" => $name, "email" => $email]
];
$subject = "Welcome on Board, Xyz Co.";
$sendgrid_mailer = new Mailer();
$sendgrid_mailer->addSender($from);
$sendgrid_mailer->addRecipient($to);
$sendgrid_mailer->addSubject($subject);
$sendgrid_mailer->addBodyContent($formated_mail_body);
$sendgrid_mailer->addReplyTo($from);
$response = $sendgrid_mailer->send();
var_dump($response);