[resolved] register_setting - textarea with line-breaks (4 posts)

  1. Valentin
    Posted 4 years ago #

    Hey there,

    I'm scripting a plugIn which can submit a specific message to an email address.
    The mail text is specified in the back-end in a textarea.

    The problem I do have is:
    In the back-end textarea line-breaks are displayed correctly,
    (Simple as line-breaks, not as "
    " tags or anything else, just a break)
    but in the mail the user receives the breaks are removed.

    Why is that?
    The functions I'm using are:

    register_setting( 'va_db_form_settings', 'va_db_form_mail_content' );
    To register the setting.

    $mail_text = get_option('va_db_form_mail_content');
    $mail_rec = get_option('va_db_form_mail');
    $mail_sender = "From: ".get_bloginfo('name')." < ".get_bloginfo('admin_email')." >\n";
    $mail_sender .= "Content-Type: text/html\n";
    $mail_sender .= "Content-Transfer-Encoding: 8bit\n";
    $message = $mail_text;
    mail($mail_rec, $mail_sub, $message, $mail_sender);

    To send the mail.

    Appreciate your help!


  2. Threecows
    Posted 4 years ago #

    Try it without the line: $mail_sender .= "Content-Type: text/html\n";

  3. Threecows
    Posted 4 years ago #

    Or (in case you want to send is as html) transfer $message to html and the Content-Type can stay as it is now (text/html).

    $message = str_replace(array("\r\n", "\n", "\r"), "<br />", $mail_text);
  4. Valentin
    Posted 4 years ago #

    Yeah thought of that myself in the end.
    Pretty dump I didn't earlier.

    $message = nl2br($mail_text);

    Thanks a lot anyway! :)

Topic Closed

This topic has been closed to new replies.

About this Topic