Search code examples
phpvariablesbreakmail-form

How to put a break in an email variable?


So I'm working on a mail form for my site and I got i working. Now I want to personalise it with a cutsom message but... I have no idea how to put line breaks in the variable message. I tried using <br />but that just prints it out as a word. So any idea's?

P.S. I may be totally wrong feel free to totally change what is in the message I just want to understand the concept.

<?php
$message =
"You recieved mail from  $mail with a question." . 
"The question contains the following:" . 
"$_POST['message'];";
?>

EDIT: @Ben Pearl Kahan answer worked for me! Thanks for the answers!


Solution

  • In double quotes, \r\n will be a new line.

    Example:

    <?php
        $message =
        "You recieved mail from  $mail with a question.\r\n" . 
        "The question contains the following:\r\n" . 
        $_POST['message'];
    ?>
    

    FYI, "$_POST['message']" is not correct concatenation; you should either process the array variable outside the string:

    "text ".$_POST["message"]." more text"
    

    or use curly brackets (NB: this will only work if your string is enclosed in double quotes):

    "text {$_POST["message"]} more text"