Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

trap and record smtp reply

 $mail->Send();
  
  echo "Mail was sent.</p>\n";
  $email_wait=0;
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
  $email_wait=2;
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
  $email_wait=3;
}

Open in new window




http://www.greenend.org.uk/rjk/tech/smtpreplies.html
is all the smtp replys

but the phpmailer try catch only catches two types of exceptions
I only get this trapped
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
and not this
echo $e->getMessage(); //Boring error messages from anything else!

but I want all types of errors to be logged
Avatar of Gary
Gary
Flag of Ireland image

This is not a php thing. Your mail server is what handles any errors (being messages from the remote mail server) and logs them
Depending on your server set up you may not have access to it with php.
For "catch" to work you have to use "try" and it's not shown in your example code.  I think I would fix that first, then create the SSCCE so we have something we can test with.  You can use var_dump() to print out the contents of the exception object.
Avatar of rgb192

ASKER

using phpmailer try/catch
how can I vardump and trap this error

try {
  $mail->IsHTML(true);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = $smtpdebug;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = $smtpauth;                  // enable SMTP authentication
$mail->SMTPSecure = $smtpsecure;                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = $port;                   // set the SMTP port for the GMAIL server
$mail->Username   = "username";  // GMAIL username
$mail->Password   = "password";            // GMAIL password  

 
  $mail->From = $mail->Username;
  $mail->FromName = "my name";
  
 $mail->AddAddress($email);




   $mail->Body='body';
   $mail->Subject='subject';
  
 $mail->Send();
  
  echo "Mail was sent.</p>\n";
  $email_wait=0;
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
  $email_wait=2;
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
  $email_wait=3;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks