Skip to content

Instantly share code, notes, and snippets.

@anytizer
Last active January 9, 2018 08:43
Show Gist options
  • Select an option

  • Save anytizer/7944429 to your computer and use it in GitHub Desktop.

Select an option

Save anytizer/7944429 to your computer and use it in GitHub Desktop.
If you want to use gmail smtp server to compose emails to send your emails, use the below code snippet to configure your PHPMailer. Each emails you send will be available in your GMail's sent folder.
<?php
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// tls on 587: strong, recommended
// ssl on 465: weak, old
// https://en.wikipedia.org/wiki/SMTPS - Deprecated
// https://myaccount.google.com/permissions
// https://myaccount.google.com/lesssecureapps
// Enable less secure password
# Your gmail login details
$mail->Username = '[email protected]';
$mail->Password = 'gmail-password';
$mail->setFrom("", "First Last");
$mail->addReplyTo("", "First Last");
$mail->addAddress("", "John Doe");
$mail->Subject = "PHPMailer GMail SMTP test";
$mail->msgHTML(file_get_contents("test/contents.html"), __DIR__);
$mail->AltBody = "This is a plain-text message body";
#$mail->addAttachment("images/logo.png");
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment