ECMall 內建的 PHPMailer 版本過舊,不支援 SMTPSecure(SSL/TLS),導致無法連接要求加密的郵件伺服器(如 Gmail、QQ 企業郵箱、Outlook 等)。
lib/phpmailer/ 為新版 PHPMailer(支援 SSL/TLS)。mail.lib.php、mail_queue.lib.php,傳遞 $SMTPSecure 參數。get_mailer() 讀取後台設定並實例化。下載新版 PHPMailer,覆蓋 core/lib/phpmailer/ 目錄。
// 建構子新增 $SMTPSecure 參數
function __construct($from, $email, $protocol, $host='', $port='', $user='', $pass='', $SMTPSecure=false) {
$this->Mailer($from, $email, $protocol, $host, $port, $user, $pass, $SMTPSecure);
}
function Mailer($from, $email, $protocol, $host='', $port='', $user='', $pass='', $SMTPSecure=false) {
// ... 內部實例化 PHPMailer
$this->mailer->SMTPSecure = $SMTPSecure; // 'ssl' 或 'tls'
// ...
}
$secure = Conf::get('email_ssl'); // 讀取後台設定
$mailer = new Mailer($sender, $from, $protocol, $host, $port, $username, $password, $secure);
<tr>
<th>郵件伺服器加密方式:</th>
<td>
{html_radios name="email_ssl" options=$email_ssl checked=$setting.email_ssl}
<label class="field_notice">需 PHP 支援 OpenSSL 擴展</label>
</td>
</tr>
// email_setting() 方法中
$this->assign('email_ssl', [
0 => Lang::get('no'),
1 => 'SSL',
2 => 'TLS',
]);
// 儲存時
$data['email_ssl'] = $_POST['email_ssl'];
// send_test_email() 方法中
$email_ssl = $_POST['email_ssl'];
$mailer = new Mailer($email_from, $email_addr, $email_type, $email_host, $email_port, $email_id, $email_pass, $email_ssl);
var email_ssl = $('input[name="email_ssl"]:checked').val();
data: '...&email_ssl=' + email_ssl
--with-openssl 或載入 openssl 擴展(php -m | grep openssl)。$mailer->SMTPAutoTLS = false; 或 SMTPOptions 忽略驗證(僅測試用)。