Note that there are some explanatory texts on larger screens.

plurals
  1. POLine breaks in a PHP contact form
    primarykey
    data
    text
    <p>I need to add a contact form to a website I'm making, and found a useful bit of code someone had kindly shared for the likes of me who have no PHP experience.</p> <p>After pasting and editing the code into the page and uploading it to a staging site, I tested it using my gmail address and it works fine. The only thing is that the email text has no line breaks in it.</p> <p><strong>Here's the code:</strong></p> <pre><code>&lt;?php if ($_POST["email"]&lt;&gt;'') { $ToEmail = 'myemailadress@gmail.com'; $EmailSubject = 'Site contact form'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"].""; $MESSAGE_BODY .= "Email: ".$_POST["email"].""; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?&gt; Your message was sent &lt;?php } else { ?&gt; &lt;form action="contactus.php" method="post"&gt; &lt;table width="400" border="0" cellspacing="2" cellpadding="0"&gt; &lt;tr&gt; &lt;td width="29%" class="bodytext"&gt;Your name:&lt;/td&gt; &lt;td width="71%"&gt;&lt;input name="name" type="text" id="name" size="32"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="bodytext"&gt;Email address:&lt;/td&gt; &lt;td&gt;&lt;input name="email" type="text" id="email" size="32"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="bodytext"&gt;Comment:&lt;/td&gt; &lt;td&gt;&lt;textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"&gt; &lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="bodytext"&gt; &lt;/td&gt; &lt;td align="left" valign="top"&gt;&lt;input type="submit" name="Submit" value="Send"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;?php }; ?&gt; </code></pre> <p><strong>This is what I receive when it arrives in my inbox:</strong></p> <blockquote> <p>Name: Mr J BloggsEmail: email@address.comComment: Comments text.</p> </blockquote> <p><strong>What I'd like is for it to instead look like this:</strong></p> <blockquote> <p>Name: Mr J Bloggs<br /> Email: email@address.com<br /> Comment: Comments text.</p> </blockquote> <p>Thanks in advance for any help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload