Support » Plugin: Easy WP SMTP » Invalid address when using \r\n in a header array

  • Resolved pikamander2

    (@pikamander2)


    https://i.imgur.com/DfXw00B.png

    Our custom plugin was failing to send out emails.

    For testing purposes, we added this to our functions.php:

    // Log wp_mail() errors
    function onMailError( $wp_error )
    {
        error_log($wp_error->get_error_message());
    }
    add_action( 'wp_mail_failed', 'onMailError', 10, 1 );

    We then looked at the error log and here’s what we saw:

    Got error 'PHP message: Invalid address: (setFrom) noreply@oursite.com \\r\\n\n',

    It turns out that we were using \r\n in our header array. According to the docs:

    When you are using the array form, you do not need to supply line breaks (“\n” or “\r\n”).

    The wording on the docs suggests that it’s optional but allowed and a competing plugin, WP Mail SMTP, seemed to be able to handle our headers just fine. So that makes me think that it’s an issue with Easy WP SMTP. If that’s the case, then the plugin should be updated to strip out unnecessary newlines to prevent errors and match the default behavior.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support mbrsolution

    (@mbrsolution)

    Hi, I have submitted a message to the developers to investigate further this issue.

    Kind regards

    Plugin Contributor Alexander C.

    (@alexanderfoxc)

    Hi.

    Thank you for your information. I have created a ticket for this issue in our inner system, so this should get addressed and most likely will be rectified and the upcoming version of the plugin. Can’t give you any ETA at the moment though, but I suspect it could be released within a week or so.

    Plugin Contributor Alexander C.

    (@alexanderfoxc)

    On the side note, you are not doing it right in your code it seems. This is how you have it right now:

    $headers[]='Name <email@example.com>\r\n';

    … but this is wrong. In order to properly add “\r\n”, those need to be enclosed in double quotes:

    $headers[]="Name <email@example.com>\r\n";
    OR
    $headers[]='Name <email@example.com>'."\r\n";

    Check PHP docs for more info http://php.net/manual/en/language.types.string.php

    • This reply was modified 10 months, 4 weeks ago by  Alexander C..

    Good eye. I wasn’t the one who wrote it, but I should have caught that.

    • This reply was modified 10 months, 4 weeks ago by  pikamander2.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Invalid address when using \r\n in a header array’ is closed to new replies.