PHP code example of rodrigoq / phpmailersendgrid
1. Go to this page and download the library: Download rodrigoq/phpmailersendgrid library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rodrigoq / phpmailersendgrid example snippets
// Import PHPMailerSendGrid classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailerSendGrid;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
Key, to do it securely check:
// https://github.com/sendgrid/sendgrid-php/blob/master/README.md
$mail->SendGridApiKey = ''; // SendGrid API Key.
//Uncomment to save email to file
// $mail->isFile();
// $mail->EmailFilePath = '/var/log/email/';
//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>.';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients.';
$mail->send();
echo 'Message has been sent.';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}