Refactored smtp sending password handling

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2023-01-23 17:32:33 +01:00
parent 68074767b7
commit 18a0ff5678
2 changed files with 7 additions and 4 deletions

View File

@ -202,6 +202,8 @@ $config['PILER_HOST'] = '0.0.0.0';
$config['PILER_PORT'] = 25; $config['PILER_PORT'] = 25;
$config['SMARTHOST'] = ''; $config['SMARTHOST'] = '';
$config['SMARTHOST_PORT'] = 25; $config['SMARTHOST_PORT'] = 25;
$config['SMARTHOST_USER'] = '';
$config['SMARTHOST_PASSWORD'] = '';
$config['SMTP_DOMAIN'] = 'yourdomain.com'; $config['SMTP_DOMAIN'] = 'yourdomain.com';
$config['SMTP_FROMADDR'] = 'no-reply@yourdomain.com'; $config['SMTP_FROMADDR'] = 'no-reply@yourdomain.com';
$config['ADMIN_EMAIL'] = 'admin@yourdomain.com'; $config['ADMIN_EMAIL'] = 'admin@yourdomain.com';

View File

@ -3,7 +3,7 @@
class ModelMailMail extends Model { class ModelMailMail extends Model {
public function send_smtp_email($smtphost, $smtpport, $yourdomain, $from, $to = [], $msg, $username = "", $password = ""){ public function send_smtp_email($smtphost, $smtpport, $yourdomain, $from, $to = [], $msg){
require_once 'Zend/Mail/Protocol/Smtp.php'; require_once 'Zend/Mail/Protocol/Smtp.php';
require_once 'Zend/Mail/Protocol/Smtp/Auth/Login.php'; require_once 'Zend/Mail/Protocol/Smtp/Auth/Login.php';
@ -32,10 +32,11 @@ class ModelMailMail extends Model {
$config['name'] = $yourdomain; $config['name'] = $yourdomain;
try { try {
if($username && $password) { $config['username'] = SMARTHOST_USER;
$config['password'] = SMARTHOST_PASSWORD;
if($config['username'] && $config['password']) {
$config['auth'] = 'login'; $config['auth'] = 'login';
$config['username'] = $username;
$config['password'] = $password;
$connection = new Zend_Mail_protocol_Smtp_Auth_Login($smtphost, $smtpport, $config); $connection = new Zend_Mail_protocol_Smtp_Auth_Login($smtphost, $smtpport, $config);
} else { } else {
$connection = new Zend_Mail_protocol_Smtp($smtphost, $smtpport, $config); $connection = new Zend_Mail_protocol_Smtp($smtphost, $smtpport, $config);