-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();
4

1 回答 1

4

我认为问题是由 Postfix 附带的“snakeoil”证书和私钥引起的。诀窍不是验证它们。这是我发现的工作:

$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
}
于 2016-10-25T20:24:30.743 回答