Search code examples
phpemailpear

PHP: PEAR Mail connecting but not sending (no error)?


I'm using PEAR's Mail package to send email from my script. I'm pretty sure I have everything connected and declared properly, but when the script runs, it just connects then immediately disconnects to my Mail server without actually sending the email.

From my Postfix logs:

Nov 18 16:15:49 mailer postfix/smtpd[30346]: connect from xxx-xxx-xxx-xxx.static.cloud-ips.com[xxx.xxx.xxx.xxx]
Nov 18 16:15:49 mailer postfix/smtpd[30346]: disconnect from xxx-xxx-xxx-xxx.static.cloud-ips.com[xxx.xxx.xxx.xxx]

What gives?


<?php

  require_once('Mail.php'); // loads in PEAR Mail package

  $mailer_params['host'] = 'mailer.example.com';
  $mailer_params['port'] = 25;
  $mailer_params['auth'] = true;
  $mailer_params['username'] = '[email protected]';
  $mailer_params['password'] = 'password';

  $mail =& Mail::factory('smtp', $mailer_params);

  $headers = array(
    'From' => '[email protected]',
    'Reply-To' => '[email protected]',
    'Subject' => 'Test Email'
  );

  $message = "whatever";

  $mail->send('Test <[email protected]>', $headers, $message);

?>

I know my Postfix server works, since I have several other applications using it without problems. The user credentials are the same in this script as they are for those other apps.

My Postfix server is using SASL_auth (configured with CRAM-MD5), if that helps. I wish I had an error message or something on either the PHP side or the Postfix side to go on, but all it does is just connect then disconnect with no other explanation.


Solution

  • I had this problem a few days ago. Try $mailer_params['auth'] = 'CRAM-MD5' and also for extra information, try $mailer_params['debug'] and run the script from the command line. If that still doesn't work, try $mail_params['auth'] = 'LOGIN'.

    Hope this helps.