postmap:警告:数据库 /etc/postfix/sasl_passwd.db 早于源文件 /etc/postfix/sasl_passwd

Arc*_*tel 1 postfix-mta smtp amazon-ec2 phpmailer amazon-web-services

我正在服务器 ubuntu 18.04 上的 amazon aws ec2 上工作...我正在尝试使用 phpmailer 发送邮件..当我单击发送邮件时,它会显示邮件已发送消息...但我没有收到任何邮件。当我转到 mail.log 文件检查它显示的错误时..它显示以下错误

postfix/smtp[32208]: warning: database /etc/postfix/sasl_passwd.db is older than source file /etc/postfix/sasl_passwd
Nov  6 05:33:52 ip-172-31-16-223 postfix/smtp[32208]: ECD64BE5CC: to=<archipatel20@gmail.com>, relay=mail.uway.in[166.62.28.116]:587, delay=1.9, delays=0.01/0.02/1.6/0.23, dsn=5.0.0, status=bounced (host mail.uway.in[166.62.28.116] said: 550 SMTP AUTH is required for message submission on port 587 (in reply to RCPT TO command))
Nov  6 05:33:52 ip-172-31-16-223 postfix/cleanup[32206]: C81D4BE60F: message-id=<20201106053352.C81D4BE60F@ip-172-31-16-223.us-east-2.compute.internal>
Nov  6 05:33:52 ip-172-31-16-223 postfix/qmgr[32200]: C81D4BE60F: from=<>, size=2669, nrcpt=1 (queue active)
Nov  6 05:33:52 ip-172-31-16-223 postfix/bounce[32210]: ECD64BE5CC: sender non-delivery notification: C81D4BE60F
Nov  6 05:33:52 ip-172-31-16-223 postfix/qmgr[32200]: ECD64BE5CC: removed
Nov  6 05:33:54 ip-172-31-16-223 postfix/smtp[32208]: C81D4BE60F: to=<crm@uway.in>, relay=mail.uway.in[166.62.28.116]:587, delay=1.8, delays=0/0/1.6/0.22, dsn=5.0.0, status=bounced (host mail.uway.in[166.62.28.116] said: 550 SMTP AUTH is required for message submission on port 587 (in reply to RCPT TO command))
Nov  6 05:33:54 ip-172-31-16-223 postfix/qmgr[32200]: C81D4BE60F: removed
Run Code Online (Sandbox Code Playgroud)

这也是我的邮件发送的 php 代码:

<?php 

$output = 'here is my html code';

if(isset($_POST["action"]))
{
include('../conn.php');

$getid = $_GET['id'];

$queryd = "SELECT * FROM `salary_sleep_gen` WHERE `id`='$getid'";

$rund = mysqli_query($conn, $queryd);

while ($rowd = mysqli_fetch_array($rund)) {
    $emaild = $rowd['email'];
    $monthbname = $rowd['month_name'];
    $yearb = $rowd['year'];
    $emp_nameb = $rowd['emp_name'];
}
include('pdf.php');
    $file_name = md5(rand()) . '.pdf';
    $html_code = '<link rel="stylesheet" href="bootstrap.min.css">';
    $html_code .= fetch_customer_data($connect);
    $pdf = new Pdf();
    $pdf->load_html($html_code);
    $pdf->render();
    $file = $pdf->output();
    file_put_contents($file_name, $file);
    
require 'class/class.phpmailer.php';


    //Create a new PHPMailer instance
   $mail = new PHPMailer();
$mail->SMTPDebug = 0;
$mail->IsMail();
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->ssl = false;
$mail->authentication = false;
$mail->addAddress($emaild);
$mail->isHTML = true;
$mail->From = 'hr@sorbeadindia.com';   //Sets the From email address for the message
 $mail->FromName = 'SORBEAD INDIA'; 

$mail->AddAttachment($file_name);
$mail->Subject = "Salary Slip -" . $monthbname." ".$yearb;
$mail->Body = "html";
$mail->AltBody = "alt";
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML("Salary Slip (".$emp_nameb.") -".$monthbname." ".$yearb);
    //Replace the plain text body with one created manually
    $mail->AltBody = 'Salary Slip ('.$emp_nameb.') -'.$monthbname.' '.$yearb;

    //send the message, check for errors
    if (!$mail->send()) {
        $message = "Mailer Error: " . $mail->ErrorInfo;
    } else {
        $message =  "Message sent!";
    }

    unlink($file_name);
}

?>
Run Code Online (Sandbox Code Playgroud)

我是 aws 的初学者,所以请帮助我并为这个错误提供一些解决方案。

Syn*_*hro 6

要修复 SASL 错误并重新生成数据库,请运行以下命令:

postmap /etc/postfix/sasl_passwd
Run Code Online (Sandbox Code Playgroud)

您的发送过程如下:

script -> local mail server -> remote mail server
Run Code Online (Sandbox Code Playgroud)

PHPMailer 负责第一步,您的邮件服务器负责第二步。因此,要解决此问题,您需要查看邮件服务器配置。postfix 日志中的其他错误表明您正在尝试通过其他服务器(在端口 587 上,这将需要 TLS 和身份验证)进行中继,但您的配置不正确,因此请搜索如何执行此操作。另请记住,AWS 对从 EC2 实例发送电子邮件施加了严格的限制;他们希望您使用他们的短信服务。

我还可以看到您使用的是非常旧版本的 PHPMailer,因此请升级

您的 PHPMailer 脚本包含以下问题:

$mail->ssl = false;
$mail->authentication = false;
$mail->isHTML = true;
Run Code Online (Sandbox Code Playgroud)

你不能只是编造一些东西并期望它神奇地发挥作用。

要关闭加密,请执行以下操作:

$mail->SMTPSecure = 0;
Run Code Online (Sandbox Code Playgroud)

要禁用身份验证,请执行以下操作:

$mail->SMTPAuth = false;
Run Code Online (Sandbox Code Playgroud)

如果您想使用 HTML,请执行以下操作:

$mail->isHTML();
Run Code Online (Sandbox Code Playgroud)

为了让您能够查看脚本传送到本地主机的进度,请启用调试输出,如下所示:

$mail->SMTPDebug = 2;
Run Code Online (Sandbox Code Playgroud)

基于PHPMailer 提供的示例的代码,或者阅读一些文档将会揭示这一点。

您的脚本很容易受到 SQL 注入攻击,因为您正在这样做:

$getid = $_GET['id'];
$queryd = "SELECT * FROM `salary_sleep_gen` WHERE `id`='$getid'";
Run Code Online (Sandbox Code Playgroud)

也就是说,你之前的:

if(isset($_POST["action"]))
Run Code Online (Sandbox Code Playgroud)

将阻止该代码工作。$_GET要么始终使用or之一$_POST,要么使用_REQUEST. 无论您做什么,请阅读 SQL 注入并修复该问题,否则您的整个数据库将面临被盗或损坏的风险。