web: update interface to PHPMailer

Depending on your mail server, PHPMailer can take various config options.
Instead of passings these as variables from project.inc to email.inc,
have project project.inc define a function make_php_mailer()
that creates a PHPMailer object, configures it as needed, and returns it.

For projects that use PHPMailer, this will require modifying your project.inc.
This commit is contained in:
David Anderson 2014-04-30 10:36:04 -07:00
parent f8ee2e51fe
commit 5d0b06136a
2 changed files with 30 additions and 19 deletions

View File

@ -25,24 +25,12 @@ require_once("../project/project.inc");
$config = get_config();
$master_url = parse_config($config, "<master_url>");
// Determine if phpmailer is installed and to be used (defined in project.inc)
if (isset($USE_PHPMAILER)) {
if ($USE_PHPMAILER) {
require_once("../inc/phpmailer/class.phpmailer.php");
}
} else {
$USE_PHPMAILER = false;
}
// send an email, using PHPMailer or not.
//
function send_email($user, $subject, $body, $body_html=null) {
global $USE_PHPMAILER;
global $PHPMAILER_HOST;
global $PHPMAILER_MAILER;
if ($USE_PHPMAILER) {
$mail = new PHPMailer();
if (function_exists("make_php_mailer")) {
require_once("../inc/phpmailer/class.phpmailer.php");
$mail = make_php_mailer();
$mail->AddAddress($user->email_addr, $user->name);
$mail->Subject = $subject;
if ($body_html) {
@ -51,10 +39,6 @@ function send_email($user, $subject, $body, $body_html=null) {
} else {
$mail->Body = $body;
}
$mail->From = EMAIL_FROM;
$mail->FromName = EMAIL_FROM_NAME;
$mail->Host = $PHPMAILER_HOST;
$mail->Mailer = $PHPMAILER_MAILER;
if (!$mail->Send()) {
echo $mail->ErrorInfo;
return false;

View File

@ -29,6 +29,33 @@ define("UOTD_ADMIN_EMAIL", "admin@$master_url");
// offensive forum posts.
define("POST_REPORT_EMAILS", "moderator1@$master_url|moderator2@$master_url");
// If you use PHPMailer, uncomment the following
// and complete the function definition based on your SMTP server
// (not all fields may be needed)
//
if (0) {
function make_php_mailer() {
$mail = new PHPMailer();
$mail->IsSMTP();
//$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "john.doe@gmail.com";
$mail->Password = "xxx";
// Google's application-specific password,
// if you are using the 2-Step Verification: 16 characters, no spaces.
// OR: Put here the regular Gmail password if you are not using the
// 2-Step Verification with your Gmail account.
// See https://support.google.com/accounts/answer/185833?hl=en";
$mail->SetFrom('admin@boincproject.com', 'John Doe');
$mail->AddReplyTo("admin@boincproject.com", "John Doe");
$mail->From = "admin@boincproject.com";
return $mail;
}
}
function project_banner($title, $prefix) {
// Put your project title and logo here
// If you include any links, prepend URL with $prefix