From 5d0b06136a32d6a767452ce2e8a6883db72f28bc Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 30 Apr 2014 10:36:04 -0700 Subject: [PATCH] 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. --- html/inc/email.inc | 22 +++------------------- html/project.sample/project.inc | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/html/inc/email.inc b/html/inc/email.inc index 6189393b18..becc511200 100644 --- a/html/inc/email.inc +++ b/html/inc/email.inc @@ -25,24 +25,12 @@ require_once("../project/project.inc"); $config = get_config(); $master_url = parse_config($config, ""); -// 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; diff --git a/html/project.sample/project.inc b/html/project.sample/project.inc index a578662d5a..badf82f3d2 100644 --- a/html/project.sample/project.inc +++ b/html/project.sample/project.inc @@ -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