Skip to content

Commit ad4ff9a

Browse files
authored
cleans up flex sendgrid sample (GoogleCloudPlatform#290)
1 parent 88db004 commit ad4ff9a

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

appengine/flexible/sendgrid/app.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
// create the Silex application
2222
$app = new Application();
2323

24-
$app['sendgrid'] = function (Application $app) {
25-
return new SendGrid($app['sendgrid.api_key']);
26-
};
27-
2824
$app->get('/', function () use ($app) {
2925
return <<
3026
@@ -38,15 +34,22 @@
3834
});
3935

4036
$app->post('/', function (Request $request) use ($app) {
41-
$mail = new SendGrid\Mail(
42-
new SendGrid\Email(null, $app['sendgrid.sender']),
43-
'This is a test email',
44-
new SendGrid\Email(null, $request->get('recipient')),
45-
new SendGrid\Content('text/plain', 'Example text body.')
46-
);
47-
/** @var SendGrid $sendgrid */
48-
$sendgrid = $app['sendgrid'];
37+
$sendgridSender = $app['sendgrid.sender'];
38+
$sendgridApiKey = $app['sendgrid.api_key'];
39+
$sendgridRecipient = $request->get('recipient');
40+
# [START send_mail]
41+
// $sendgridApiKey = 'YOUR_SENDGRID_API_KEY';
42+
// $sendgridSender = '[email protected]';
43+
// $sendgridRecipient = '[email protected]';
44+
$sender = new SendGrid\Email(null, $sendgridSender);
45+
$recipient = new SendGrid\Email(null, $sendgridRecipient);
46+
$subject = 'This is a test email';
47+
$body = new SendGrid\Content('text/plain', 'Example text body.');
48+
$mail = new SendGrid\Mail($sender, $subject, $recipient, $body);
49+
// send the email
50+
$sendgrid = new SendGrid($sendgridApiKey);
4951
$response = $sendgrid->client->mail()->send()->post($mail);
52+
# [END send_mail]
5053
if ($response->statusCode() < 200 || $response->statusCode() >= 300) {
5154
return new Response($response->body(), $response->statusCode());
5255
}

0 commit comments

Comments
 (0)