tags:

views:

437

answers:

2

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.xxx.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.

A: 

Here is the first thing I'd try, see if you can get an exception error from PHP:

<?php

try {


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

      $mailer_params['host'] = 'mailer.xxx.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);

    } catch (Exception $e) {
        echo "Exception: " . $e->getMessage();
    }

And I have some other questions, out of curiousity:

  1. You mentioned your postfix server works with other applications, are they on the same server? Is this a remote request, or an application on the same server as the mail

  2. Can you reverse engineer anything on the working server to see what's being done differently?

  3. Are you sending email from the same domain as what's on the server?

Some of the basis behind question 1 and 3 is the fact that a great deal of hosts either block or put restrictions on mailing. This is because spammers will create accounts and abuse them until they are banned. This makes sending mail difficult for the rest of us honest people, but it happens every day.

I hope this gives some food for thought, reply back and let's see if we can find the problem.

Jeremy Morgan
Thanks for the response. I tried adding in the try/catch statement, but it threw no error, yet I got the same behavior. This script is copied verbatim from another remote server (not on the same system as Postfix) which works fine. The server I'm trying this script on is also not on the same server as my Postfix system. And yes: I'm sending mail on the same domain as what's configured on my Postfix server. Any other suggestions?
neezer
+1  A: 

Hi, 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.

AK
Changing the 'auth' type to `CRAM-MD5` did the trick! Thanks!
neezer
As an aside, I've also discovered that you must have the PEAR `Auth_SASL` package installed.
neezer