php-general Digest 15 Nov 2012 15:52:56 -0000 Issue 8041

Topics (messages 319709 through 319710):

Re: Pear Mail - Trap for errors?
        319709 by: tamouse mailing lists
        319710 by: Rick Dwyer

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Wed, Nov 14, 2012 at 7:19 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:
> Hello all.
>
> I have some Pear Mail code composing an email and sending it to an external 
> smtp server for sending.
>
> The issue is determining whether that external server actually accepted the 
> mail or not.  In the IF(PEAR… code below, it will return success even if I 
> leave the $to value empty.  However, if I remove the smtp username or 
> password, it will return an error indicating it could not reach the remote 
> server.  So the Pear::IsError function seems to only reflect if the intended 
> server was accessible… and not if the intended server accepted the outgoing 
> email for delivery.
>
> Anyone have experience with the scenario below… specifically with determining 
> if the smtp server accepted the mail for delivery?
>
> Thanks for any info.
>
> --Rick
>
>  require_once "Mail.php";
>
>  $from = "f...@address.com";
>  $to = "t...@address.com";
>  $subject = "Hello!";
>  $body = "Hello!";
>
>  $host = "mail.host.net";
>  $username = "myuser";
>  $password = "mypass";
>
>  $headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
>  $smtp = Mail::factory('smtp',array ('host' => $host,'auth' => 
> true,'username' => $username,'password' => $password));

I'd suggest putting a check here to see if $smtp is a PEAR::Error
object as well:

if (PEAR::isError($smtp)) {
  echo ("<p>" . $smtp->getMessage() . "</p>");
  // die or return or skip the next part, whatever
} else {

>  $mail = $smtp->send($to, $headers, $body);
>
>  if (PEAR::isError($mail)) {
>    echo("<p>" . $mail->getMessage() . "</p>");
>   } else {
>    echo("<p>Message successfully sent!</p>");
>   }

}


> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
On Nov 14, 2012, at 10:48 PM, tamouse mailing lists <tamouse.li...@gmail.com> 
wrote:

> On Wed, Nov 14, 2012 at 7:19 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:
>> Hello all.
>> 
>> I have some Pear Mail code composing an email and sending it to an external 
>> smtp server for sending.
>> 
>> The issue is determining whether that external server actually accepted the 
>> mail or not.  In the IF(PEAR… code below, it will return success even if I 
>> leave the $to value empty.  However, if I remove the smtp username or 
>> password, it will return an error indicating it could not reach the remote 
>> server.  So the Pear::IsError function seems to only reflect if the intended 
>> server was accessible… and not if the intended server accepted the outgoing 
>> email for delivery.
>> 
>> Anyone have experience with the scenario below… specifically with 
>> determining if the smtp server accepted the mail for delivery?
>> 
>> Thanks for any info.
>> 
>> --Rick
>> 
>> require_once "Mail.php";
>> 
>> $from = "f...@address.com";
>> $to = "t...@address.com";
>> $subject = "Hello!";
>> $body = "Hello!";
>> 
>> $host = "mail.host.net";
>> $username = "myuser";
>> $password = "mypass";
>> 
>> $headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
>> $smtp = Mail::factory('smtp',array ('host' => $host,'auth' => 
>> true,'username' => $username,'password' => $password));
> 
> I'd suggest putting a check here to see if $smtp is a PEAR::Error
> object as well:
> 
> if (PEAR::isError($smtp)) {
>  echo ("<p>" . $smtp->getMessage() . "</p>");
>  // die or return or skip the next part, whatever
> } else {

Same result… which is to say no error returned even for messages sent with no 
email in the to address field.

--Rick


--- End Message ---

Reply via email to