Solved

trap and record smtp reply

Posted on 2013-05-13
5
197 Views
Last Modified: 2013-05-19
 $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
0
Comment
Question by:rgb192
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39162492
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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39162870
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.
0
 

Author Comment

by:rgb192
ID: 39163039
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

0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39164416
When your script uses the catch() statement it identifies two important pieces of data.  First, it identifies the kind of exception it can catch and it will not catch other kinds of exceptions.  Second it identifies the variable name that will be assigned to the exception object.  Man pages here:
http://php.net/manual/en/language.exceptions.php
http://php.net/manual/en/language.exceptions.extending.php

This little script illustrates what happens when you've extended the built-in PHP Exception class.
http://www.laprbass.com/RAY_try_throw_catch.php?q=0
http://www.laprbass.com/RAY_try_throw_catch.php?q=1
http://www.laprbass.com/RAY_try_throw_catch.php?q=2
http://www.laprbass.com/RAY_try_throw_catch.php?q=3

<?php // RAY_try_throw_catch.php
error_reporting(E_ALL);
echo "<pre>";

// DEMONSTRATE A TRY WITH MULTIPLE CATCH BLOCKS
// EXAMPLE: RAY_try_throw_catch.php?q=1
// http://php.net/manual/en/reserved.exceptions.php
// http://php.net/manual/en/language.exceptions.php
// http://php.net/manual/en/language.exceptions.extending.php

Class ScrewUP
{
    // CONSTRUCTOR SETS A CODE PROPERTY FOR THE OBJECT
    public function __construct($q)
    {
        // CHOOSE AN INTEGER VALUE FROM ZERO TO THREE
        $this->code = 0;
        if (!empty($q)) $this->code = floor($q % 4);
    }

    // THIS WILL THROW SOME KIND OF EXCEPTION BASED ON THE CODE
    public function hiccup()
    {
        // THESE EXCEPTIONS WILL BE CAUGHT
        if ($this->code == 0) throw new Exception_zero('Hello');
        if ($this->code == 1) throw new Exception_one('World');

        // THIS WILL BE AN UNCAUGHT EXCEPTION: FATAL ERROR
        if ($this->code == 2) throw new Exception_two('Foobar');

        // THIS WILL BE AN UNEXTENDED EXCEPTION
        throw new Exception('Naked');
    }
}

Class Exception_Zero extends Exception
{
    public function __construct($x)
    {
        parent::__construct();
        echo "Exception Zero: $x ";
    }
}

Class Exception_One extends Exception
{
    public function __construct($x)
    {
        parent::__construct();
        echo "Exception One: $x ";
    }
}

// INSTANTIATE THE CLASS USING THE URL q= VARIABLE
$x = new Screwup($_GET['q']);

// RUN THE TRY/CATCH LOGIC TO THROW AN EXCEPTION
try
{
    $x->hiccup();
}
catch (exception_One $e)
{
    echo "I Have Caught Exception Number: $x->code ";
    var_dump($e);
}
catch (exception_Zero $e)
{
    echo "I Have Caught Exception Number Zero ";
    var_dump($e);
}
catch (exception $e)
{
    echo "I Have Caught an UnExtended Exception ";
    var_dump($e);
}

Open in new window

Edited to replace the code snippet.  HTH, ~Ray
0
 

Author Closing Comment

by:rgb192
ID: 39180160
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CA single sign on 2 72
FILTER_SANITIZE_NUMBER_INT takes out the 0 when staring a number with 0 19 44
Php pie charts 3 26
updating the date data 12 19
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now