我正在使用 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,但仍然出现相同的错误。
这是我的 postfix 配置文件(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,但我不确定这是否会对其产生任何影响。
提前致谢。