PHP PEAR Mail SMTP response on success

93 Views Asked by At

Here is my code:

$mail_object = Mail::factory('smtp', $params);

$send = $mail_object->send($email, $headers, $body);

if (PEAR::isError($send)) {

  $error_message = $send->getMessage();

So, when there is an error, I get the error message. But I need the response from the SMTP server on success. The success message is usually something like "250 ok queued as xxx". I need to see this message. Is there a way?

1

There are 1 best solutions below

0
cweiske On

The SMTP driver writes this number in the "queued_as" property:

https://github.com/pear/Mail/blob/master/Mail/smtp.php#L350

    if (preg_match("/ queued as (.*)/", $args, $queued)) {
        $this->queued_as = $queued[1];
    }

You can access this property on your $mail_object after sending.