-
Notifications
You must be signed in to change notification settings - Fork 376
Expand file tree
/
Copy pathsend_first_email.php
More file actions
40 lines (31 loc) · 1.13 KB
/
send_first_email.php
File metadata and controls
40 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// require our config file
require_once 'config.php';
// require composer autoload so we can use sendgrid
require 'vendor/autoload.php';
// create new sendgrid mail
$email = new \SendGrid\Mail\Mail();
// specify the email/name of where the email is coming from
$email->setFrom( FROM_EMAIL, FROM_NAME );
// set the email subject line
$email->setSubject( "Sending with SendGrid is Fun" );
// specify the email/name we are sending the email to
$email->addTo( TO_EMAIL, TO_NAME );
// add our email body content
$email->addContent( "text/plain", "and easy to do anywhere, even with PHP" );
$email->addContent(
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
// create new sendgrid
$sendgrid = new \SendGrid( SENDGRID_API_KEY );
try {
// try and send the email
$response = $sendgrid->send( $email );
// print out response data
print $response->statusCode() . "\n";
print_r( $response->headers() );
print $response->body() . "\n";
} catch ( Exception $e ) {
// something went wrong so display the error message
echo 'Caught exception: '. $e->getMessage() ."\n";
}