0

I am using pear to send email using the code below, on the first time through I get this error every time:

"Failed to set sender: aa@bb.com [SMTP: Invalid response code received from server (code: -1, response: )]"

If I debug and set the execution point back to 'Re-run from here' after the send, it works fine - almost like something is not initialised properly first time round - anyone have any ideas on this?

require_once "Mail.php";

function SendEMail() {

     $from = "Sender Sender <sender@example.com>";
     $to = "AA BB <aa@bb.com>";
     $subject = "Test";
     $body = "This is a test";

     $host = "myhost";

     $headers = array ('From' => $from,
                        'To' => $to,
                        'Subject' => $subject);

     //Re-run from here        
     $smtp =& Mail::factory('smtp',
       array ('host' => $host,
         'auth' => false,
         'username' => '',
         'password' => ''));

     $mail = $smtp->send($to, $headers, $body);

     if (PEAR::isError($mail)) {
        $s = $mail->getMessage();
     }
 } 
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
A_L
  • 1,116
  • 2
  • 11
  • 25

1 Answers1

0

Use wireshark to find out which response you really get from the server. Maybe the server has activated greylisting, so that you can't send a mail the first time.

cweiske
  • 30,033
  • 14
  • 133
  • 194
  • There isn't anything like that as I'm running a personal smpt for testing , it works fine with php's built-in smtp but just behaves strangely with the pear version – A_L Aug 12 '13 at 11:53
  • so you say you can't use wireshark to analyze network traffic because what exactly? – cweiske Aug 12 '13 at 13:10
  • I didn't say that I can't use wireshark, just that there cannot be any greylisting or similar problems. I can only assume that this is some weird incompatibility between the pear library and my smtp as it works with eg. google fine. – A_L Aug 14 '13 at 08:48
  • that's why I told to check what error message you really get from the server. Without that information, it is impossible to find out what's wrong. – cweiske Aug 14 '13 at 08:53