Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Unhappy php form not sending data

    I have created a questionnaire with 8 questions. When I click submit after entering data I do not get any errors but don't get an e-mail with the form data either.

    PHP Code:
    <?php
    if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to "myemail@gmail.com";
    $email_subject "Survey Test";
     
    $question1 $_POST['question1']; // required
    $question2 $_POST['question2']; // required
    $question3 $_POST['question3']; // required
    $question4 $_POST['question4']; // required
    $question5 $_POST['question5']; // required
    $question6 $_POST['question6']; // required
    $question7 $_POST['question7']; // required
    $question8 $_POST['question8']; // required
     
    $email_message "Form details below.\n\n";
     
    function 
    clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return 
    str_replace($bad,"",$string);
    }
     
    $email_message .= "question1 : ".clean_string($question1)."\n";
    $email_message .= "question2 : ".clean_string($question2)."\n";
    $email_message .= "question3 : ".clean_string($question3)."\n";
    $email_message .= "question4 : ".clean_string($question4)."\n";
    $email_message .= "question5 : ".clean_string($question5)."\n";
    $email_message .= "question6 : ".clean_string($question6)."\n";
    $email_message .= "question7 : ".clean_string($question7)."\n";
    $email_message .= "question8 : ".clean_string($question8)."\n";
    // create email headers
    $headers 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' phpversion();
    if(@
    mail($email_to$email_subject$email_message$headers))
    {
    //if email sending is successful
    //Note the below message variable. It will be echoed at the bottom of the form
    $complete_message 'Thank you for your enquiry. We will contact you shortly.';
     }
    }
    ?>

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    I have created e-mail headers :

    PHP Code:
    // create email headers
    $headers 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' phpversion();
    if(@
    mail($email_to$email_subject$email_message$headers))
    {
    //if email sending is successful
    //Note the below message variable. It will be echoed at the bottom of the form
    $complete_message 'Thank you for your enquiry. We will contact you shortly.';
     }
    }
    ?> 
    These are the same headers I have used for several forms which all work. This one does not.
    Last edited by Mehdi72; 04-19-2013 at 12:14 PM.

  • #4
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    it all depends on your hosting and sendmail's configuration and mail server your hosting have. some of them will allow you to fake "From:" header, but most of them wont since that's considered fraud.
    safest way is to don't touch headers at all

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    i meant patryk's post removing the headers

    Quote Originally Posted by patryk View Post
    try like that:
    PHP Code:
    // create email headers
    mail($email_to$email_subject$email_message); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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