
我正在用 dovecot 運行 postfix。我正在嘗試使用 PHP Pear Mail 套件發送電子郵件,但無法讓它運作。我得到的錯誤是這樣的:authentication failure [SMTP: STARTTLS failed (code: 220, response: 2.0.0 Ready to start TLS)]
。
我正在使用 php 7.4 cli 運行它。這是文件(mail-test.php):
<?php
require_once "Mail.php";
$from = "[email protected]";
$to = '[email protected]';
$host = "mail.fildom.net";
$port = "25";
$username = 'username';
$password = 'password';
$subject = "test";
$body = "test";
$headers = array ('From' => $from, 'To' => $to,'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo("Message successfully sent!\n");
}
?>
我在網路上嘗試了很多修復方法,例如設定 verify_peer 和 verify_peer_name 但沒有一個起作用。我嘗試將連接埠設為 567,但它只是給出了相同的錯誤。
這是我的後綴設定檔(main.cf):
# GENERAL SETTINGS
smtpd_banner = $myhostname ESMTP $mail_name
biff = no
append_dot_mydomain = no
readme_directory = no
# SMTP SETTINGS
smtp_use_tls=yes
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# SMTPD SETTINGS
smtpd_use_tls=yes
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_tls_cert_file=/etc/ssl/cert.pem
smtpd_tls_key_file=/etc/ssl/key.pem
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
# SASL SETTINGS
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
# VIRTUAL MAIL BOX AND LMTP SETTINGS
virtual_transport = lmtp:unix:private/dovecot-lmtp
virtual_mailbox_domains = /etc/postfix/virtual_mailbox_domains
# OTHER SETTINGS
myhostname = mail.fildom.net
myorigin = /etc/mailname
mydestination = localhost.$mydomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
我從 CloudFlare 取得了 SSL 憑證。我還在 CloudFlare 上設定並啟用了 Authenticated Origin Pulls,但我不確定這是否對其有任何影響。
提前致謝。