Support » Developing with WordPress » Determine if message is send or not

  • Guido

    (@guido07111975)


    Hi!

    I’m wondering whether this is a proper way to determine if wp_mail (phpmailer) has send a message or not?

    
    if ( wp_mail($to, $subject, $message, $headers) ) == true {
    	echo 'message send';
    } else {
    	echo 'message not send';
    }
    

    It seems to work though. Tested it on local install and live server.

    Guido

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steve Stern

    (@sterndata)

    Guardian of the Interwebs

    According to https://developer.wordpress.org/reference/functions/wp_mail/,

    “A true return value does not automatically mean that the user received the email successfully. It just only means that the method used was able to process the request without any errors.”

    Guido

    (@guido07111975)

    Hi Steve,

    Yes, I understand that it’s not a way to determine whether user has received it or not, but I only want a way to determine if mail was properly send or not.

    I did not find much info about this, besides the codex. And other contact form plugins use their own ways to determine this. So I was wondering whether my way is solid or not?

    Guido

    Moderator Steve Stern

    (@sterndata)

    Guardian of the Interwebs

    It’s as solid as possible without being able to control the MTA or view its logs.

    Guido

    (@guido07111975)

    Not tested but I think this is better, don’t need the extra check on true value:

    
    if ( wp_mail($to, $subject, $message, $headers) ) {
    	echo 'message send';
    } else {
    	echo 'message not send';
    }
    

    Guido

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Determine if message is send or not’ is closed to new replies.