Last active
November 8, 2019 19:23
-
-
Save dalslandan200/640053a94e0dd46773f5cb751620969a to your computer and use it in GitHub Desktop.
G-suite with TLS for SMF, using AUTH LOGIN with passed username and password (partial file)
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
// Main partion of code, enabling SMF 2.0.15 via SMTP with TLS to work successfully. | |
// Remember this only works when using username and password via the SMTP services from G-suite. | |
// This if-clause and partions of the code is found within the function smtp_mail() | |
if ($modSettings['mail_type'] == 1 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') | |
{ | |
// Determine the hostname we want to send with each Extended hello and hello. | |
if (function_exists('gethostname') && gethostname() !== false) | |
$helo = gethostname(); // Server hostname | |
elseif (function_exists('php_uname')) | |
$helo = php_uname('n'); // Server hostname | |
elseif (array_key_exists('SERVER_NAME',$_SERVER) && !empty($_SERVER['SERVER_NAME'])) | |
$helo = $_SERVER['SERVER_NAME']; // Web server hostname | |
if (empty($helo)) | |
$helo = $webmaster_email; | |
// EHLO could be understood to mean encrypted hello... | |
if (server_parse('EHLO ' . $helo, $socket, null) == '250') { | |
// Send STARTTLS to enable encryption | |
if (!server_parse('STARTTLS', $socket, '220')) | |
return false; | |
// Enable the encryption | |
// php 5.6+ fix | |
$crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; | |
if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) | |
{ | |
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; | |
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; | |
} | |
if (!@stream_socket_enable_crypto($socket, true, $crypto_method)) | |
return false; | |
// Send the EHLO command again | |
if (!server_parse('EHLO ' . $helo, $socket, null) == '250') | |
return false; | |
if (!server_parse('AUTH LOGIN', $socket, '334')) | |
return false; | |
// Send the username and password, encoded. | |
if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) | |
return false; | |
// The password is already encoded ;) | |
if (!server_parse($modSettings['smtp_password'], $socket, '235')) | |
return false; | |
} | |
elseif (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250')) | |
return false; | |
} | |
else | |
{ | |
// Just say "helo". | |
if (!server_parse('HELO ' . $modSettings['smtp_host'], $socket, '250')) | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment