Last active
October 7, 2016 03:26
-
-
Save paoga87/73f07482a9df5485c36738a6be2ea4b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Using PHP's mail() function--> | |
<?php | |
$to = 'someone@example.com'; | |
$subject = 'Subject line goes here'; | |
$message = 'Hi, this is me!'; | |
$headers = 'From: info@example.com' . "\r\n" . | |
'Reply-To: no-reply@example.com' . "\r\n" . | |
'X-Mailer: PHP/' . phpversion(); | |
mail($to, $subject, $message, $headers); | |
?> | |
<!-- Using cur with Sendgrid --> | |
<?php | |
$url = 'https://api.sendgrid.com/'; | |
$user = 'USERNAME'; | |
$pass = 'PASSWORD'; | |
$params = array( | |
'api_user' => $user, | |
'api_key' => $pass, | |
'to' => 'john@contoso.com', | |
'subject' => 'testing from curl', | |
'html' => 'testing body', | |
'text' => 'testing body', | |
'from' => 'anna@contoso.com', | |
); | |
$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); | |
// print everything out | |
print_r($response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment