How to add line breaks to $email[‘body’] when using auto_core_update_email hook

I am using the auto_core_update_email hook to modify the auto update email sent by WordPress. However I cannot figure out how to add line breaks to the email body. Here’s my code:

function example_filter_auto_update_email($email) {
    $email['to'] = array('[email protected]', '[email protected]');
    $email['subject'] = 'Auto Update';
    $email['body'] = 'Hello,%0D%0A'
      . 'Lorem ipsum.%0D%0A'
      . 'Many thanks,%0D%0A'
      . 'WordPress';

    return $email;
}

add_filter('auto_core_update_email', 'example_filter_auto_update_email', 1);

I have also tried using:
<br />, \r\n, as well as %0D%0A, seen above. However, in each case the string is just printed in my email client like this:

Hello%0D%0ALorem Ipsum%0D%0AMany thanks%0D%0AWordPress

How can I get line breaks printed in my auto update emails? If it helps the emails are being sent by SMTP.

Thanks a lot!

2 Answers
2

Don’t use single quotes with escape sequences like \r, \n and so on. Use double quotes:

$a="Hello, " . "\n";
$b = "Good Bye, \n";

See Double quoted strings in PHP.

Leave a Comment