开发者

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

开发者 https://www.devze.com 2022-12-12 09:44 出处:网络
I\'m using PEAR\'s Mail package to send email from my scri开发者_JAVA百科pt. I\'m pretty sure I have everything connected and declared properly, but when the script runs, it just connects then immedia

I'm using PEAR's Mail package to send email from my scri开发者_JAVA百科pt. 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'] = 'user@mailer.example.com';
  $mailer_params['password'] = 'password';

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

  $headers = array(
    'From' => 'user@example.com',
    'Reply-To' => 'user@example.com',
    'Subject' => 'Test Email'
  );

  $message = "whatever";

  $mail->send('Test <other.user@example.com>', $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.


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.


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.example.com';
      $mailer_params['port'] = 25;
      $mailer_params['auth'] = true;
      $mailer_params['username'] = 'user@mailer.example.com';
      $mailer_params['password'] = 'password';

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

      $headers = array(
        'From' => 'user@example.com',
        'Reply-To' => 'user@example.com',
        'Subject' => 'Test Email'
      );

      $message = "whatever";

      $mail->send('Test <other.user@xxx.com>', $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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号