Reputation: 63
i am working on amazon aws ec2 on server ubuntu 18.04...i am trying to send mail using phpmailer ..when i click to send mail then it shows me mail sent message ...but i didn't received any mails. and when i go to the mail.log file to check what error it shows ..it shows following errors
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=<[email protected]>, 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=<[email protected]>, 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
And also here is my php code for mail send:
<?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 = '[email protected]'; //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);
}
?>
i am beginner for aws so Please help me and give some solution for this error.
Upvotes: 1
Views: 12424
Reputation: 37770
To fix the SASL error and regenerate the database, run this command:
postmap /etc/postfix/sasl_passwd
Your sending process works like this:
script -> local mail server -> remote mail server
PHPMailer is responsible for the first step, your mail server the second. So to fix this, it's your mail server config you need to look at. The other errors in your postfix log suggest that you're trying to relay through some other server (on port 587, which will require both TLS and authentication), but that your configuration for that is incorrect, so search for how to do that. Also bear in mind that AWS imposes severe limits on sending email from EC2 instances; they want you to use their SMS service.
I can also see you're using a very old version of PHPMailer, so upgrade.
Your PHPMailer script contains these problems:
$mail->ssl = false;
$mail->authentication = false;
$mail->isHTML = true;
You can't just make stuff up and expect it to magically work.
To turn off encryption, do this:
$mail->SMTPSecure = 0;
To disable authentication, do this:
$mail->SMTPAuth = false;
To say you want to use HTML, do this:
$mail->isHTML();
To allow you to see the progress of your script's delivery to localhost, enable debug output like this:
$mail->SMTPDebug = 2;
Basing your code on the examples provided with PHPMailer, or reading some docs would have revealed this.
Your script is vulnerable to SQL injection attacks because you're doing this:
$getid = $_GET['id'];
$queryd = "SELECT * FROM `salary_sleep_gen` WHERE `id`='$getid'";
That said, your earlier:
if(isset($_POST["action"]))
will prevent that code from ever working. Either consistently use one of $_GET
or $_POST
, or use _REQUEST
. Whatever you do, go read up on SQL injection and fix that or risk your entire database being stolen or trashed.
Upvotes: 9