-1

I already setup postfix in my debian linux VPS. I can send email via ssh console using postfix. I can send email using PHPMailer using my gmail account. I can receive email in my debian linux VPS account.

Then I want to send email using PHPMailer via Postfix using my debian linux vps account. But it's failed with log below.

SERVER -&gt; CLIENT: <br>
CLIENT -&gt; SERVER: EHLO android<br>
SERVER -&gt; CLIENT: <br>
SMTP ERROR: EHLO command failed: <br>
SMTP NOTICE: EOF caught while checking if connected<br>
SMTP Error: Could not connect to SMTP host.<br>

How to send email using PHPMailer using postfix ? should i use sasl ?

My sendmail.php

$mail = new PHPMailer;
$mail->isSMTP();
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Subject = 'hello postfix phpmailer';
$mail->msgHTML(file_get_contents('contentemail.html'), dirname(__FILE__));
$mail->Host = 'yyyy.zzzz.com';
$mail->Username = "xxxx";
$mail->setFrom('xxxx@yyyy.zzzz.com', 'Ceramah Islam');
$mail->addReplyTo('xxxx@yyyy.zzzz.com', 'Ceramah Islam');
$mail->Password = "aaaaaa";
$mail->addAddress('bbbb@gmail.com', 'bbbb');
$mail->send();
Plugie
  • 1,289
  • 17
  • 25
  • Can you post the complete output with SMTPDebug = 4, and make sure you're using the latest PHPMailer. – Synchro Oct 08 '16 at 07:17

1 Answers1

4

I think the problem is caused by the "snakeoil" certificate and private key that come with Postfix. The trick is not to verify them. Here is what I found worked:

$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "localhost";
$mail->Port = 25;
$mail->SMTPSecure = "tls";
$mail->SMTPOptions = array
  (
    'ssl' => array
    (
      'verify_peer' => false,
      'verify_peer_name' => false,
      'allow_self_signed' => true
    )
  );
$mail->setFrom('server@example.org', 'My Server');
$mail->addAddress('user@example.com', 'My User'); 
$mail->Subject = 'Message from PHPMailer and Postfix';
$mail->Body = 'Whatever';
if ($mail->send())
// SMTP message send success
{
// Put success logic here
} 
else
// SMTP message send failure
{
// Put failure logic here
}
dcamero
  • 41
  • 1