Results 1 to 2 of 2

Thread: need help with form

  1. #1
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help with form

    I made a form to send emails with but i can't get it to make email clients understand theres html in the email

    code:
    Code:
    <?php
    function spamcheck($field)
      {
      //filter_var() sanitizes the e-mail 
      //address using FILTER_SANITIZE_EMAIL
      $field=filter_var($field, FILTER_SANITIZE_EMAIL);
      
      //filter_var() validates the e-mail
      //address using FILTER_VALIDATE_EMAIL
      if(filter_var($field, FILTER_VALIDATE_EMAIL))
        {
        return TRUE;
        }
      else
        {
        return FALSE;
        }
      }
    
    if (isset($_REQUEST['email']))
      {//if "email" is filled out, proceed
    
      //check if the email address is invalid
      $mailcheck = spamcheck($_REQUEST['email']);
      if ($mailcheck==FALSE)
        {
        echo "Invalid input";
        }
      else
        {//send email
        $name = $_REQUEST['name'] ;
        $email = $_REQUEST['email'] ; 
        $to = $_REQUEST['to'] ; 
        $subject = $_REQUEST['subject'] ;
        $message = $_REQUEST['message'] ;
        mail(
        "$to", 
        "Subject: $subject",
        $message="<html><body>".$_POST['message_html']."</body></html>", "From: $email" );
        echo "Thank you for using our mail form $name";
        }
      }
    else
      {//if "email" is not filled out, display the form
      echo 
      "
      <script language='javascript1.2'>
       // attach the editor to the textarea with the identifier 'textarea1'.
       WYSIWYG.attach('mailtext');
      </script>
      
      <form method='post' action=''>
      Name:   <input name='name' type='text' /><br /><br />
      Email:   <input name='email' type='text' /><br /><br />
      To:   <input name='to' type='text' /><br /><br />
      Subject:   <input name='subject' type='text' /><br /><br />
      Message:<br />
      <textarea id='mailtext' name='message_html' style='height: 170px; width: 475px;'>
      </textarea>  
      <br />
      <input type='submit' value='Send' />
      </form>";
      }
    ?>

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Try to set the proper headers for html and add as a fourth argument to the mail() method.

    This part:
    PHP Code:
     mail(
        
    "$to"
        
    "Subject: $subject",
        
    $message="<html><body>".$_POST['message_html']."</body></html>""From: $email); 

    ..should be:
    PHP Code:
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $headers .= "From: {$email}"\r\n"// Construct headers
    mail(
        
    "$to"
        
    "Subject: $subject",
        
    $message="<html><body>".$_POST['message_html']."</body></html>",$headers); 
    Hope that helps.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •