How to break lines when sending an email?

Asked

Viewed 4,401 times

2

How do I break lines in an email that will be sent via PHP ?

If I use <br/> It only works that the email arrives in the spam box.

Part of PHP code:

if(count($errors) == 0){
    $user = get_userdata( $status );
    $user->set_role('commentator_commenter');
    $from = get_option('admin_email');  
    $headers = __( 'De', 'commentator' ).' '.$from . "</br>";  
    $subject = __( 'Registrado com sucesso', 'commentator' );
    $msg = __( 'Você foi registrado com sucesso!<br/>', 'commentator' ).__( 'Seus dados:<br/>', 'commentator' ).__( 'Usuário:', 'commentator' ).$username.__( '<br/>Senha:', 'commentator' ).$password;
    add_filter( 'wp_mail_content_type', 'set_html_content_type' );
    wp_mail( $email, $subject, $msg, $headers );
    remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
    $arr = array(
        'message' => __( 'Registro com sucesso, verifique em seu e-mail a sua senha', 'commentator' )
    );
}
  • 3

    It’s not because of <br> which is in the box of spam. The spacing depends on the content-type that you are using to send the email.

  • Hello @Jorgeb. I noticed this, I saw that the problem is in the characters that are accented, can not use á, ã, õ, é, etc... In case I have to change set_html_content_type for set_text_content_type ?

  • 1

    I use Content-Type: text/plain; charset=utf-8 so I don’t have those problems. This might help you: http://wordpress.org/support/topic/wp_mail_content_type

  • How could I implement plain text in the above code?

  • Turn your comment into a reply :P

Show 1 more comment

3 answers

3


It’s not because of <br> which is in the box of spam.

The line break depends on the content-type that you are using to send the email.

You can use Content-Type: text/plain; charset=utf-8 so you don’t have those problems.

Or you can do it like this:

add_filter('wp_mail_content_type',create_function('', 'return "text/plain"; '));

Source

2

If you’re using plain text messaging, can use the following:

//...
$msg = __( 'Você foi registrado com sucesso!', 'commentator' ) 
    . "\n" . __( 'Seus dados:', 'commentator' )
    . "\n" .__( 'Usuário:', 'commentator' ). $username
    . "\n" . __( 'Senha:', 'commentator' ). $password;
  • How so plain text ?

  • You can send messages in plain text or HTML. What kind of message you send?

  • Text only, informing the data to log in.

  • 1

    then the way I wrote it will work! :D

  • Thank you! ......

0

You can break lines using \n , I can’t tell you if this gets you out of the spam box, because this is much more complex than more or less tags in the body of the message.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.