dt2015 2017-03-12 22:21
浏览 79

Sendgrid提供两个响应代码......不寻常

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);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集