PHP SendGrid - not getting an answer

I'm having huge problems with SendGrid working on my Azure subscription. He just does not send emails! I followed the textbooks, and the code is essentially copied from them, but letters are not sent to my address. The code below is used for my contact form.

My main problem is that echo $responseit gives nothing - not even space.

<?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 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 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();
+4
source share

All Articles