Skip to content

Commit 8cdd8c3

Browse files
committed
php send emails with sendgrid api
1 parent dbedf93 commit 8cdd8c3

17 files changed

Lines changed: 1040 additions & 0 deletions

sendgrid/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"sendgrid/sendgrid": "~7"
4+
}
5+
}

sendgrid/composer.lock

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sendgrid/config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
define( 'SENDGRID_API_KEY', 'YOUR-SENDGRID-API-KEY' );
3+
4+
define( 'FROM_EMAIL', 'YOUR-FROM-EMAIL' );
5+
define( 'FROM_NAME', 'YOUR-FROM-EMAIL-NAME' );
6+
7+
define( 'TO_EMAIL', 'YOUR-TO-EMAIL' );
8+
define( 'TO_NAME', 'YOUR-FROM-EMAIL-NAME' );

sendgrid/send_first_email.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
require_once 'config.php';
3+
require 'vendor/autoload.php';
4+
5+
$email = new \SendGrid\Mail\Mail();
6+
$email->setFrom( FROM_EMAIL, FROM_NAME );
7+
$email->setSubject( "Sending with SendGrid is Fun" );
8+
$email->addTo( TO_EMAIL, TO_NAME );
9+
$email->addContent( "text/plain", "and easy to do anywhere, even with PHP" );
10+
$email->addContent(
11+
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
12+
);
13+
$sendgrid = new \SendGrid( SENDGRID_API_KEY );
14+
15+
try {
16+
$response = $sendgrid->send( $email );
17+
print $response->statusCode() . "\n";
18+
print_r( $response->headers() );
19+
print $response->body() . "\n";
20+
} catch ( Exception $e ) {
21+
echo 'Caught exception: '. $e->getMessage() ."\n";
22+
}

sendgrid/vendor/autoload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer/autoload_real.php';
6+
7+
return ComposerAutoloaderInit03a890a83cb481a9849199f1fb3f6887::getLoader();

0 commit comments

Comments
 (0)