How can I send my form in php with HTML?

by Colton
5 replies
Code:
if($_POST['name']!='' && $_POST['company']!='' && $_POST['e_mail']!='' && $_POST['telephone']!='' && $_POST['message']!='' && valid_email($_POST['e_mail'])==TRUE && strlen($_POST['message'])>15)
    {
        $to = 'email@yahoo.com';
        $headers =     'From: '.$_POST['e_mail'].''. "\r\n" .
                'Reply-To: '.$_POST['e_mail'].'' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
        
        
        $subject = "Message From website.com";
        $message = htmlspecialchars($_POST['message']); 
        $message .= 'Company Name:'.htmlspecialchars($_POST['company']); 
        $message .= 'Name:'.htmlspecialchars($_POST['name']);  
        $message .= 'Telephone Number:'.htmlspecialchars($_POST['telephone']); 
        
        if(mail($to, $subject, $message, $headers))
That's what I have so far, but when I send the email through the form it's all bunched together. I want it to be laid out nice and easy to read. How can I do that? Thanks.
#form #html #php #send
  • Profile picture of the author Oakleaf
    Try adding a few newline chars at the end of the message var like so

    $message = htmlspecialchars($_POST['message'])."\n";
    $message .= 'Company Name:'.htmlspecialchars($_POST['company'])."\n";
    $message .= 'Name:'.htmlspecialchars($_POST['name'])."\n";
    $message .= 'Telephone Number:'.htmlspecialchars($_POST['telephone'])."\n";
    {{ DiscussionBoard.errors[2579028].message }}
    • Profile picture of the author CBSnooper
      I'd put a < br > between the ' and Company Name, Name and Telephone number. This will make those appear on a new line.


      $message = htmlspecialchars($_POST['message']);
      $message .= '<br>Company Name:'.htmlspecialchars($_POST['company']);
      $message .= '<br>
      Name:'.htmlspecialchars($_POST['name']);
      $message .= '<br>
      Telephone Number:'.htmlspecialchars($_POST['telephone']);
      [/CODE]
      {{ DiscussionBoard.errors[2579029].message }}
  • Profile picture of the author phpbbxpert
    HTML breaks will not work unless it is sent as HTML

    $message = htmlspecialchars($_POST['message']) . "\r\n";
    $message .= 'Company Name:'.htmlspecialchars($_POST['company']) . "\r\n" ;
    $message .= 'Name:'.htmlspecialchars($_POST['name']) . "\r\n" ;
    $message .= 'Telephone Number:'.htmlspecialchars($_POST['telephone']) . "\r\n" ;
    {{ DiscussionBoard.errors[2579105].message }}
  • Profile picture of the author dealbert.net
    Try wufoo.com. It has free form generator, very nice ones too. The fee-based ones allows to create more than 10 fields in a form.

    I'm not affiliate with wufoo.
    {{ DiscussionBoard.errors[2579275].message }}
  • Profile picture of the author Colton
    Thanks for the help guys!
    {{ DiscussionBoard.errors[2582029].message }}

Trending Topics