How can I send my form in php with HTML?

by 5 replies
6
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.
#programming #form #html #php #send
  • 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";
    • [1] reply
    • 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]
  • 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" ;
  • 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.
  • Thanks for the help guys!

Next Topics on Trending Feed

  • 6

    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.