dovecot saslとTLSを使用してpostfixサーバーをインストールしました。 PHPコードからメールを送信しようとすると問題が発生します。ログイン認証タイプを「smtp」として使用すると、サーバーは資格情報なしで接続を受け入れます。これを「ログイン」に変更すると、サーバーは自分の資格情報を確認し、ユーザーまたはパスワードが間違っていると警告します。
SMTP認証とは何ですか?認証されたユーザーのみを許可するようにpostfixを設定する方法は?
私のmain.cfファイルの関連コード
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
virtual_alias_domains = $mydomain
virtual_alias_maps = hash:/etc/postfix/virtual
zend mailパスワードが間違っているかパスワードが間違っていてもメールを送信できるPHPコードの一部です。
$options = new SmtpOptions([
'host' => 'mail.host.com',
'port' => '25',
'connection_class' => 'smtp',
'connection_config' => [
'username' => 'user',
'password' => 'bad-password',
'ssl' => 'tls'
]
]);
ベストアンサー1
次の電子メールスクリプトは、SMTP認証を使用してPHP電子メールを送信するために使用されます。 SMTP認証で電子メールを送信するには、ポート465または587を使用する必要があります。
SMTPのデフォルトポートはポート25です。ポート25は、SMTP認証なしでサーバーから電子メールを送信することを意味します。
ここからphpmailerをダウンロードしてくださいhttps://github.com/PHPMailer/PHPMailer次に、以下のエンコーディングを使用します。
<?php
require_once "vendor/autoload.php";
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "[email protected]";
$mail->Password = "super_secret_password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "[email protected]";
$mail->FromName = "Full Name";
$mail->addAddress("[email protected]", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}