Skip to content

Instantly share code, notes, and snippets.

@FL-Retiree
Created April 11, 2017 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FL-Retiree/e65f142bf7c902f6168d52294a96bf41 to your computer and use it in GitHub Desktop.
Save FL-Retiree/e65f142bf7c902f6168d52294a96bf41 to your computer and use it in GitHub Desktop.
GetSimple/SMTP Mail Functionality
/* ----------------------------------------------------------------------
This code fragment and addition to the GetSimple config file is designed to provide the capability to use SMTP mail when sending from
the GetSimple core application, not from plugins. For example, when sending a mail generated by a user request to "Reset Password"
GetSimple uses the built in PHP Mail() function only. Many hosting environments are now requiring that PHP scripts only use SMTP for
security reasons and thus this suggested change...
------------------------------------------------------------------------- */
STEP #1 -
Add the following 2 lines to GSConfig.php:
# Change the default mailer to PHPMailer()
define('PHPMAILER', TRUE);
STEP #2 -
Install PHPMailer package from https://github.com/PHPMailer/PHPMailer/archive/master.zip in my Web Root.
STEP #3 -
Last step is changes to GetSimple\admin\inc\basic.php beginning with:
// ==========================================================================
include ($_SERVER["DOCUMENT_ROOT"] . '\\PHPMailer\\PHPMailerAutoload.php');
// ==========================================================================
And finally - In the Function Sendmail() replace all the code following the last line containing "$headers .=" with:
// ======================= START PHP CODE ====================
if (defined('PHPMAILER')) {
$mail = new PHPMailer;
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
// $mail->SMTPDebug = 2;
$mail->IsHTML(true);
//Ask for HTML-friendly debug output
// $mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "MY_SMTP_HOST.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = MY_REQUIRED_PORT;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "MY_SMTP_USERNAME";
//Password to use for SMTP authentication
$mail->Password = "MY_SMTP_PASSWORD";
//Set who the message is to be sent from
$mail->setFrom('MY_SENTFROM_EMAIL', '');
//Set an alternative reply-to address
$mail->addReplyTo('MY_REPLYTO_EMAIL', '');
//Set who the message is to be sent to
$mail->addAddress($to, '');
//Set the subject line
$mail->Subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
$mail->Body = $message;
//send the message, check for errors
if (!$mail->send()) {
return 'success';
} else {
return 'error';
}
} // End if defined('PHPMAILER')
else {
if( @mail($to,'=?UTF-8?B?'.base64_encode($subject).'?=',"$message",$headers) ) {
return 'success';
} else {
return 'error';
}
}
=============== END PHP CODE ===============
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment