我正在使用以下代码通过SendGrid发送电子邮件。电子邮件发送成功,但是$response
始终为空。我正在尝试获取/存储消息ID。我尝试过打开/关闭SSL,也尝试过使用SSL的本地计算机和生产服务器。
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sendgrid.com/v3/mail/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $sg_data,
CURLOPT_POST => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.getenv('SENDGRID_API_KEY'),
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
var_dump($response,curl_error($curl),curl_getinfo($curl));
curl_close($curl);
同样,电子邮件发送了,但是var_dump
给了我:
string(0) "" string(0) "" array(26) { ["url"]=> string(37) "https://api.sendgrid.com/v3/mail/send" ["content_type"]=> NULL ["http_code"]=> int(202) ["header_size"]=> int(446) ["request_size"]=> int(520) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.321982) ["namelookup_time"]=> float(3.8E-5) ["connect_time"]=> float(0.017802) ["pretransfer_time"]=> float(0.070089) ["size_upload"]=> float(306) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(950) ["download_content_length"]=> float(0) ["upload_content_length"]=> float(306) ["starttransfer_time"]=> float(0.321954) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(13) "167.89.115.21" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(8) "10.0.1.3" ["local_port"]=> int(60184) }