Sending Plain Text Email Using Sendgrid
suggest changeThese samples use the older SendGrid\Email client. Current sendgrid-php sends mail with SendGrid\Mail\Mail.
Basic Text Email
<?php
$sendgrid = new SendGrid("YOUR_SENDGRID_API_KEY");
$email = new SendGrid\Email();
$email->addTo("recipient@example.com")
->setFrom("sender@example.com")
->setSubject("Subject Text")
->setText("This is a sample basic text email using SendGrid.");
$sendgrid->send($email);
Adding additional recipients, CC recipients, BCC recipients
<?php
$sendgrid = new SendGrid("YOUR_SENDGRID_API_KEY");
$email = new SendGrid\Email();
$email->addTo("recipient1@example.com", "Recipient Name")
->addCc("recipient2@example.com")
->addBcc("recipient3@example.com")
->setFrom("sender@example.com")
->setSubject("Subject Text")
->setHtml("<html><body><p><b>This paragraph is bold.</b></p><p><i>This text is italic.</i></p></body></html>");
$sendgrid->send($email);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents