• Resolved 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 Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    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.”

    Thread Starter 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 Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

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

    Thread Starter 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.