Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Auto response php form

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #168048
    clickstars
    Participant

    I do have a normal php contact form (as below) but I want to add auto response to the user who press the submit button on the form. Anyone could help?

    below is my php script:

    <?php
    if(isset($_POST[’email’])) {

    // EDIT THE BELOW TWO LINES AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "You Got Mail!";
    
    function errorMesg() {
        // Error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "&lt;br /&gt;&lt;br /&gt;";
        echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;";
        die();
    }
    
    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['phone']) ||
        !isset($_POST['subject']) ||
        !isset($_POST['comments'])) {
        errorMesg();       
    }
    
    $name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $phone = $_POST['phone']; // required
    $subject = $_POST['subject']; // required
    $comments = $_POST['comments']; // required
    
    
    $email_message = "Form details from Painter2u.com as below.\n\n";
    
    
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
    
    $email_message .= "Name: ".clean_string($name)."\n\n";
    
    $email_message .= "Email: ".clean_string($email_from)."\n\n";
    
    $email_message .= "Phone: ".clean_string($phone)."\n\n";
    
    $email_message .= "Subject: ".clean_string($subject)."\n\n";
    
    $email_message .= "Comments: ".clean_string($comments)."\n";
    

    // create email headers

    $headers = ‘From: ‘.$email_from.”\r\n”.
    ‘Reply-To: ‘.$email_from.”\r\n” .
    ‘X-Mailer: PHP/’ . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>

    <!– include your own success html here –>

    Thank you for contacting us. We will be in touch with you very soon.

    <?php
    }
    ?>

    #168748
    nigelc
    Participant

    Something like this should work:

    &lt;?php
    if(isset($_POST['email'])) {
    
    // EDIT THE BELOW TWO LINES AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "You Got Mail!";
    
    function errorMesg() {
        // Error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "&lt;br /&gt;&lt;br /&gt;";
        echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;";
        die();
    }
    
    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['phone']) ||
        !isset($_POST['subject']) ||
        !isset($_POST['comments'])) {
        errorMesg();       
    }
    
    $name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $phone = $_POST['phone']; // required
    $subject = $_POST['subject']; // required
    $comments = $_POST['comments']; // required
    
    $email_message = "Form details from Painter2u.com as below.\n\n";
    
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
    
    $email_message .= "Name: ".clean_string($name)."\n\n";
    
    $email_message .= "Email: ".clean_string($email_from)."\n\n";
    
    $email_message .= "Phone: ".clean_string($phone)."\n\n";
    
    $email_message .= "Subject: ".clean_string($subject)."\n\n";
    
    $email_message .= "Comments: ".clean_string($comments)."\n";
    
    // create email headers
    
    $headers = ‘From: ‘.$email_from.”\r\n”.
    ‘Reply-To: ‘.$email_from.”\r\n” .
    ‘X-Mailer: PHP/’ . phpversion();
    
    /* Prepare autoresponder subject */
    
    $respond_subject = "Thank you for contacting us!";
    
    /* Prepare autoresponder message */
    
    $respond_message = "Thank you for contacting Your Organisation!
    
    We will get back to you as soon as possible.
    
    If you would like to sign up to our newsletter please click the link below.
    
    http://www.website.com/newsletter2.html
    
    Yours sincerely,
    
    Your Name
    
    Your Organisation
    
    www.website.com/
    
    ";
    /* Send the response message using mail() function */
    
    mail($email_from, $respond_subject, $respond_message);
    
    /* Send the message using mail() function */
    
    mail($email_to, $email_subject, $email_message, $headers);
    
    //redirect to the 'thank you' page
    header('Location: ./contact-form-thank-you.html');
    ?&gt;
    

    Couple of changes.

    1 The form on submission will redirect to to a Thank You page. Much better way of doing it.

    2 The response message does not contain any user submitted data. If user data is included it is possible for someone to use your form to spam a 3rd party by entering their email address and that target will get a message from your site advertising fake sunglasses, dodgy handbags and keepy-uppy pills.

    #235448
    unsignedradiorocks
    Participant

    I am trying to do the same thing. I have a php form with upload capabilities but I think it is coded somewhat differently than the post above. I tried the suggested solution above to no avail. Could someone please help me out with this?

    I need an autoreponse for the the listed code. Any help would be appreciated:

    <?PHP
    /*
        Contact Form from HTML Form Guide
        This program is free software published under the
        terms of the GNU Lesser General Public License.
        See this page for more info:
        http://www.html-form-guide.com/contact-form/contact-form-attachment.html
    */
    require_once("./include/fgcontactform.php");
    require_once("./include/captcha-creator.php");
    
    $formproc = new FGContactForm();
    $captcha = new FGCaptchaCreator('scaptcha');
    
    $formproc->EnableCaptcha($captcha);
    
    //1. Add your email address here.
    //You can add more than one receipients.
    $formproc->AddRecipient('[email protected]'); //<<---Put your email address here
    
    
    //2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
    // and put it here
    $formproc->SetFormRandomKey('XsHVufPpgD9Epwl');
    
    $formproc->AddFileUploadField('song','mp3',20000);
    
    if(isset($_POST['submitted']))
    {
       if($formproc->ProcessForm())
       {
            $formproc->RedirectToURL("thank-you.php");
       }
    }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>
          <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
          <title>Contact us</title>
          <link rel="STYLESHEET" type="text/css" href="contact.css" />
          <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
          <script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
    </head>
    <body link=white alink=whit vlink=white>
    
    <center>
    <!-- Form Code Start -->
    <form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
    
    <fieldset >
    <legend>Song Submission Form</legend>
    
    <input type='hidden' name='submitted' id='submitted' value='1'/>
    <input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
    <input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
    
    <center>
    <table cellpadding=10>
    <tr>
    <td>
    <div class='short_explanation'>* required fields</div>
    
    <div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
    <div class='container'>
        <label for='name' >Artist Name*: </label><br/>
        <input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
        <span id='contactus_name_errorloc' class='error'></span>
    </div>
    <div class='container'>
        <label for='email' >Email Address*:</label><br/>
        <input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
        <span id='contactus_email_errorloc' class='error'></span>
    </div>
    <div class='container'>
        <label for='website' >Website*:</label><br/>
        <input type='text' name='website' id='website' value='<?php echo $formproc->SafeDisplay('website') ?>' maxlength="100" /><br/>
        <span id='contactus_website_errorloc' class='error'></span>
    </div>
    </td>
    
    <td>
    <div class='container'>
        <label for='song' >Your Song:</label><br/>
        <input type="file" name='song' id='song' /><br/>
        <span id='contactus_song_errorloc' class='error'></span>
    </div>
    <div class='container'>
        <div><img alt='Captcha image' src='show-captcha.php?rand=1' id='scaptcha_img' /></div>
        <label for='scaptcha' >Enter the code above here:</label>
        <input type='text' name='scaptcha' id='scaptcha' maxlength="10" /><br/>
        <span id='contactus_scaptcha_errorloc' class='error'></span>
        <div class='short_explanation'>Can't read the image?
        <a href='javascript: refresh_captcha_img();'>Click here to refresh</a>.</div>
    </div>
    </td>
    <td>
    
    <div class='container'>
        <input type='submit' name='Submit' value='Submit' />
    </div>
    </td>
    </tr>
    </table>
    All submissions MUST be named in the following format: Artist_Name_-_Song_Title.mp3 using an underscore in place of any spaces. Any submissions not formatted correctly will be ignored. Thank you.
    </center>
    
    </fieldset>
    </form>
    </center>
    <!-- client-side Form Validations:
    Uses the excellent form validation script from JavaScript-coder.com-->
    
    <script type='text/javascript'>
    // <![CDATA[
    
        var frmvalidator  = new Validator("contactus");
        frmvalidator.EnableOnPageErrorDisplay();
        frmvalidator.EnableMsgsTogether();
        frmvalidator.addValidation("name","req","Please provide your name");
    
        frmvalidator.addValidation("website","req","Please provide your website URL");
    
        frmvalidator.addValidation("email","req","Please provide your email address");
    
        frmvalidator.addValidation("email","email","Please provide a valid email address");
    
        frmvalidator.addValidation("song","file_extn=mp3","Upload .mp3 files only.");
    
        frmvalidator.addValidation("scaptcha","req","Please enter the code in the image above");
    
        document.forms['contactus'].scaptcha.validator
          = new FG_CaptchaValidator(document.forms['contactus'].scaptcha,
                        document.images['scaptcha_img']);
    
        function SCaptcha_Validate()
        {
            return document.forms['contactus'].scaptcha.validator.validate();
        }
    
        frmvalidator.setAddnlValidationFunction("SCaptcha_Validate");
    
        function refresh_captcha_img()
        {
            var img = document.images['scaptcha_img'];
            img.src = img.src.substring(0,img.src.lastIndexOf("?")) + "?rand="+Math.random()*1000;
        }
    
    
    
    // ]]>
    </script>
    
    
    
    
    
    </body>
    </html>
    
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.