Skip to main content
Inspiring
September 17, 2012
Question

Creating next lines in html

  • September 17, 2012
  • 5 replies
  • 988 views

My php contact form is working properly but whenever my client receives an email from the form, the email looks very disorganized because all of the contact information that the user has submittted, comes in one line.

Here is my php code

                $To = "fakemail";

                $Subject = "fake message";

                $From = "fake user";

                $Message = "Name: " . $Name. "Email " . $Email. "Phone" . $Phone. "Options" . $Options. "Comments"  . $Comments;

                $Headers = "From: ". $from . "<" . $to. ">\r\n";  

                $Headers .= "Reply-To: " . $email_text . "\r\n"; 

                $Headers .= "Return-path: ". $email_text;

                $result = mail($To, $Subject, $Message, $Headers);

I would like to add the "\n" after each  .$Name,  .$Email, etc variable so when my client receives the message it will come out like

Name: Bob

Email: fake@email.com

Phone: 123345

etc....

Thanks in advanced

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

David_Powers
Inspiring
September 19, 2012

Very simple:

$Message = "Name: " . $Name. "\r\n\r\nEmail: " . $Email. "\r\n\r\nPhone: " . $Phone. "\r\n\r\nOptions: " . $Options. "\r\n\r\nComments: "  . $Comments;

sudarshan.t
Inspiring
September 17, 2012

More than line breaks, a table would look best. Here's the code:

    $mailBody = '<table border="1">';

    $mailBody .= '<tr>';

    $mailBody .= '<td>Name :</td><td>'.$fullName.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>Title :</td><td>'.$title.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>Company :</td><td>'.$company.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>City :</td><td>'.$city.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>State :</td><td>'.$state.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>Postal Code :</td><td>'.$postal.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>Country :</td><td>'.$country.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>Phone Number :</td><td>'.$phoneNo.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>E-Mail :</td><td>'.$eMail.'</td>';

    $mailBody .= '</tr><tr>';

    $mailBody .= '<td>Message :</td><td>'.$message.'</td>';

    $mailBody .= '</tr>';

    $mailBody .= '</table>';

   

   

David_Powers
Inspiring
September 19, 2012

Sudarshan Thiagarajan wrote:

More than line breaks, a table would look best. Here's the code:

A table won't work unless the headers also set the Content-type to text/html. By default, the mail() function uses plain text.

sudarshan.t
Inspiring
September 19, 2012

David, I overlooked OP's headers and failed to mention this in my reply. Sorry about that and thanks for pointing it out!