使用sendgrid和php发送电子邮件,出现错误,我真的不知道这意味着什么

时间:2019-11-01 23:48:50

标签: php email sendgrid

我正在尝试使用sendgrid和php发送电子邮件,通过联系表单获取电子邮件和用户名,但是当我单击“发送”时,我会在网络标签中收到以下错误消息:

  

错误->    202数组([0] => HTTP / 1.1 202接受的[1] =>服务器:nginx [2] =>日期:Fri,01 Nov 2019 18:00:56 GMT [3] =>内容长度:0 [ 4] =>连接:保持活动状态[5] => X-Message-Id:LrCEWclVQ4KuB-OnRXz1bw [6] => Access-Control-Allow-Origin:https://sendgrid.api-docs.io [7] => Access-Control- Allow-Methods:POST [8] => Access-Control-Allow-Headers:授权,内容类型,代表,x-sg-elas-acl [9] => Access-Control-Max-Age: 600 [10] => X-No-CORS原因:https://sendgrid.com/docs/Classroom/Basics/API/cors.html [11] => [12] =>)

我的代码:

if (isset($_POST['name']) && isset($_POST['email']) )
{ if(!empty($_POST['name']) && !empty($_POST['email'])){
//variables
$name = $_POST['name']; $mail = $_POST['email']; $body = $_POST['message']; $subject = 'Contato Codesign';

$email = new \SendGrid\Mail\Mail(); $email->setFrom( $mail, $name); $email->setSubject("teste"); $email->addTo('novoprojeto@codesignestudio.com.br', $name); $email->addContent("text/plain", $body); $email->addContent( "text/html", "$body" ); $sendgrid = new \SendGrid($API_KEY); 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"; }

}else{ echo "Preencha todos os campos"; } }

0 个答案:

没有答案