PHP Form Mailer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    PHP Form Mailer

    Hello Everyone:

    This is an contact form

    I thought I solved the problem.
    What I need to is have the sender email address posted on the email ie the headers of an email
    Right not the headers say
    Info
    it use to have some numbers 1439581.1546653 which are related to the hosting site.
    Hope that made sense.

    Code:
    <?php
    
    if(isset($_POST['email'])) {
         
        // EDIT THE 2 LINES BELOW AS REQUIRED
    	$email_to = "info@abc.com" ;
        $headers= "From: .$email";
        $email_subject = "Web Support Inquiry";
    
         
         // function died($error) {
            // your error code can go here
         //   echo "We are very sorry, but there were error(s) found with the form you submitted. ";
         //   echo "These errors appear below.<br /><br />";
         //   echo $error."<br /><br />";
         //   echo "Please go back and fix these errors.<br /><br />";
         //   die();
      //  }
         
        // validation expected data exists
        if(!isset($_POST['comments']) ||
            !isset($_POST['Your_name']) ||
            !isset($_POST['email'])) //{
            died('We are sorry, but there appears to be a problem with the form you submitted.');      
       // }
       
        $comments = $_POST['comments']; // required
        $Your_name = $_POST['Your_name']; // required
        $email = $_POST['email']; // required
    
    
       // $error_message = "";
      //  $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    //  if(!preg_match($email_exp,$email_from)) {
     //   $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
     // }
     //   $string_exp = "/^[A-Za-z .'-]+$/";
     // if(!preg_match($string_exp,$first_name)) {
     //   $error_message .= 'The First Name you entered does not appear to be valid.<br />';
     // }
      //if(!preg_match($string_exp,$company)) {
     //   $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
    //  }
    //  if(strlen($error_message) > 0) {
     //   died($error_message);
    //  }
      
    //email body information   
      
    	$email_message = "Web Support Inquir.\n\n";
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
        $email_message .= "Comments:    ".clean_string($comments)."\n";
        $email_message .= "Name:    ".clean_string($Your_name)."\n";
        $email_message .= "Email:      ".clean_string($email)."\n";
        
         
    // create email headers
    
    $headers = 'From: '.$email."\r\n".
    
    'Reply-To: '.$email_to."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    
    @mail($email_to, $email_subject, $email_message, $headers ); 
      header( 'Location: http://www.abc.com/thankyou.html' ) ;
    ?>
     
    <!-- include your own success html here -->
     
    <?php
    }
    ?>
    Thanks
    Damon
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    I figured it out, had to deal with the header.

    Line 7 $headers= "From: .$Your_name";
    Line 62 $headers = 'From: '.$Your_name."\ r\n".

    Comment

    Working...