PHP SendGrid - 没有得到回复

时间:2015-05-17 10:55:40

标签: php azure curl sendgrid

我在使用SendGrid处理Azure订阅时遇到了一些大问题。它根本不发送电子邮件!我已经按照教程进行操作,代码基本上是从它们复制的,但是电子邮件没有发送到我的地址。以下代码用于我的联系表格。

我主要担心的是echo $response什么都没有 - 甚至没有空格。

<?php
// use actual sendgrid username and password in this section
$url = 'https://api.sendgrid.com/'; 
$user = 'removed'; // place SG username here
$pass = 'removed'; // place SG password here
$to = 'removed@removed.com';

// grabs HTML form's post data; if you customize the form.html parameters then you will need to reference their new new names here
$name = $_POST['name']; 
$email = $_POST['email']; 
$subject = $_POST['subject']; 
$message = $_POST['message'];

// note the above parameters now referenced in the 'subject', 'html', and 'text' sections
// make the to email be your own address or where ever you would like the contact form info sent
$params = array(
    'api_user'  => $user,
    'api_key'   => $pass,
    'to'        => $to, // set TO address to have the contact form's email content sent to
    'subject'   => $subject, // Either give a subject for each submission, or set to $subject
    'html'      => $message,
    'text'      => $message,
    'from'      => $email, // set from address here, it can really be anything
  );

//curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
$request =  $url.'api/mail.send.json';

// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// obtain response
$response = curl_exec($session);
curl_close($session);

// Redirect to thank you page upon successful completion, will want to build one if you don't already have one available
//header('url=removed.htm'); // feel free to use whatever title you wish for thank you landing page, but will need to reference that file name in place of the present 'thanks.html'
echo '<script language="javascript">';
echo 'alert("Message Sent.")';
echo '</script>';

echo 'DEBUG: Contact Form works but not fully operational.';
// print everything out
echo $response;

exit();

0 个答案:

没有答案