phplist 內建 phpmailer 版本較舊(1.73,2005 年),不支援 Gmail 要求的 SSL/TLS 驗證,導致「Mailer Error: The following From address failed」錯誤,實際上是根本無法連上 SMTP 伺服器。
下載 PHPMailer 5.1,建立測試腳本 test_gmail.php:
<?php
require 'class.phpmailer.php';
require 'class.smtp.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 1; // 關鍵:開啟除錯輸出
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'your@gmail.com';
$mail->Password = 'your_app_password'; // 需使用應用程式密碼
$mail->From = 'your@gmail.com';
$mail->FromName = 'Webmaster';
$mail->Subject = 'Test';
$mail->MsgHTML('Test body');
$mail->AddAddress('your@gmail.com');
if (!$mail->Send()) {
echo "Error: " . $mail->ErrorInfo;
} else {
echo "Sent!";
}
若出現 Unable to find the socket transport "ssl",表示 PHP 未啟用 OpenSSL。
php.ini,取消註解:extension=php_openssl.dllssleay32.dll、libeay32.dll 複製到 C:\Windows\System32\(或加入系統 PATH)# Ubuntu/Debian sudo apt-get install php-openssl sudo systemctl restart apache2 # CentOS/RHEL sudo yum install php-openssl sudo systemctl restart httpd
class.phpmailer.php、class.smtp.php 覆蓋 lists/admin/phpmailer/ 同名檔案lists/admin/class.phplistmailer.php 約第 36 行,在 $this->Host = PHPMAILERHOST; 前加入:
$this->IsSMTP(); // 新增
$this->SMTPAuth = true;
$this->SMTPSecure = "ssl"; // 新增
$this->Helo = getConfig("website");
$this->Host = PHPMAILERHOST;
$this->Port = 465; // 新增:Gmail SSL 埠
config.php 設定正確:
define("PHPMAILERHOST", 'smtp.gmail.com');
$phpmailer_smtpuser = 'your@gmail.com';
$phpmailer_smtppassword = 'your_app_password';
$mail->SMTPDebug = 1; 可輸出詳細 SMTP 交互過程,快速定位連線/認證/SSL 問題| 錯誤訊息 | 原因 | 解決 |
|---|---|---|
| Unable to find socket transport "ssl" | PHP 未載入 OpenSSL | 啟用 extension=php_openssl.dll,複製 DLL 到 System32 |
| Connection timed out | 網路不通/防火牆阻擋 | 檢查 465 埠連通性,雲端安全組規則 |
| Authentication failed | 帳密錯誤/未用應用程式密碼 | 產生 Gmail 應用程式密碼 |
| From address failed | 舊版 phpmailer 不支援 SSL | 升級 phpmailer 5.1+,設定 SMTPSecure=ssl |