Skip to content

Instantly share code, notes, and snippets.

@kublaios
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kublaios/b8b778191a14d6ca0bb1 to your computer and use it in GitHub Desktop.
Save kublaios/b8b778191a14d6ca0bb1 to your computer and use it in GitHub Desktop.
Sample PHPMailer Script with Gmail Settings
<?php
function sendMailerMail($recipient, $subject, $email_content)
{
// include phpmailer class and initialize
require_once __dir__ . 'class.phpmailer.php';
$mail = new PHPMailer();
// //
// set up mail server settings
// sample for gmail
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = "tls";
// //
// set up sender and receiver
$mail->Username = "sender@gmail.com";
$mail->Password = "password";
$mail->SetFrom($from, "Sender Name");
$mail->FromName = 'Sender Name';
$mail->AddAddress($recipient);
// //
// set up mail
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $email_content;
// //
if($mail->Send()) {
// mail sent
return true;
} else {
// see what the error is
echo $mail->ErrorInfo;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment