Last active
August 29, 2015 14:23
-
-
Save kublaios/b8b778191a14d6ca0bb1 to your computer and use it in GitHub Desktop.
Sample PHPMailer Script with Gmail Settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = "[email protected]"; | |
$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