How to create a email feedback form for my existing website?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • impin
    New Member
    • Jul 2010
    • 127

    How to create a email feedback form for my existing website?

    users fill the feedback form and send mails to us.

    i wnat to ue php mail() function. plz help how to use the php script? what are the things i need for that?

    i am new to this plz help...
  • londres9b
    New Member
    • Apr 2010
    • 106

    #2
    It's very simple actually.

    Code:
    [B]<?php
    $to      = 'feedback@yoursite.com';
    $subject = 'the subject';
    $message = 'User Message';
    $headers = 'From: $userEmail';
    
    mail($to, $subject, $message, $headers);[/B]
    ?>
    I suppose you know how how to get the $message, the $userEmail and possibly the $subject from the feedback html form. If not just say so.

    Comment

    • impin
      New Member
      • Jul 2010
      • 127

      #3
      simply i can upload the php script to my website?

      i want to know other than the html form and php script what else i need?

      i upload both the form and script to my website. but the mail is not reciving...

      this is my contact form
      Code:
       <form id="contacts-form" method="post" action="mail.php" onSubmit="return validateForm(this)">
                                                   <fieldset>
                                                      <div class="field"><label>Full Name:</label><input type="text" value="" name="name"/> <font color="#FF0000" size="+1">*</font></div> 
                                                      <div class="field"><label>E-mail:</label><input type="text" value="" name="email"/> <font color="#FF0000" size="+1">*</font></div>
                                                      <div class="field"><label>Phone:</label><input type="text" value="" name="phone"/> <font color="#FF0000" size="+1"></font></div>
                                                      <div class="field"><label>Subject:</label><input type="text" value="" name="subject"/></font></div>
                                                     
                                                      <div class="field"><label>Services:</label><select name="services">
        <option>------------Select------------</option>                                              
        <option>Call Center Services</option>
        <option>Data Entry Services</option>
        <option>KPO Services</option>
        <option>Health Care Services</option>
        <option>Software Development</option>
      </select> 
        <font color="#FF0000" size="+1">*</font>
      </div>
                                                      <div class="field"><label>Message:</label><textarea name="message" cols="" rows=""></textarea> </div>
                                                                                                    
                                                      <div align="center"><input type="submit" value="SUBMIT"/></font></div>
                                                      
                                                      <!--<div class="alignright"><a href="mail.php" class="button" onclick="document.getElementById('contacts-form').submit()"><em><b>Submit</b></em></a>
                                                      </div>-->
                                                   </fieldset>
                                                </form>

      this is my mail.php script

      Code:
      <?php
      //if(isset($_POST['email'])) {
      	
      	
      	$email_to = "impin@in.com"; //mail id
      	$email_subject = "Outsource Projects to India";
      	
      	
      	$name = $_POST['name']; 
      	$email = $_POST['email'];
      	$phone = $_POST['phone']; 
      	$services = $_POST['services'];
      	$message = $_POST['message'];
      	
      			
      	
      	
      	$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 .= "Name: ".clean_string($name)."\n";
      	$email_message .= "Email: ".clean_string($email)."\n";
      	$email_message .= "Phone: ".clean_string($phone)."\n";
      	$email_message .= "Services: ".clean_string($services)."\n";
      	$email_message .= "Message: ".clean_string($message)."\n";
      	
      
      // create email headers
      $headers = 'From: '.$email."\r\n".
      'Reply-To: '.$email."\r\n" .
      'X-Mailer: PHP/' . phpversion();
      ini_set("sendmail_from","impin@in.com"); 
      mail($email_to, $email_subject, $email_message, $headers);  
      ?>
      is anything wrong in the code? or what else the problem?

      Comment

      • impin
        New Member
        • Jul 2010
        • 127

        #4
        now my website is online. but the mails only not going...

        Code:
        if (mail($email_to, $email_subject, $email_message, $headers))
        {
        	echo "<h4>Thank you for sending email</h4>";
        } else {
          echo "<h4>Can't send email</h4>";
        }
        ?>
        i get result as "cant send email".

        so what i do?

        Comment

        • londres9b
          New Member
          • Apr 2010
          • 106

          #5
          Well before anything let's make sure you realize that you have this on your code:

          Code:
          [B]//[/B]if(isset($_POST['email'])) {
          Was that a mistake or what? If that line is commented if means it will never be executed. And so your script will never run.

          Comment

          • impin
            New Member
            • Jul 2010
            • 127

            #6
            even if this line is executed, still i wont get mail.

            still i get the result as i cant send mail...

            Code:
            if(isset($_POST['email'])) {
            in this code 'email' is what? it is email.php?! or its a keyword? in myacse my php file is mail.php.
            so i have to change the code like this?
            Code:
            if(isset($_POST['mail'])) {
            or i can use the same code
            Code:
            if(isset($_POST['email'])) {
            plz help

            Comment

            • londres9b
              New Member
              • Apr 2010
              • 106

              #7
              Code:
              if(isset($_POST['[B]email[/B]'])) {
              That 'email' comes from the form, the field with name='email'.

              You use that to to tell the script to run only if the form as been submitted. Normally you'd use $_POST['submit'] but you can use any other form field.

              Not sure exactly what the problem was (probably that if in the beginning) but the code now works.

              Code:
              <?php
              if(isset($_POST['email'])) {
               
               
                  $email_to = "impin@in.com"; //mail id
                  $email_subject = "Outsource Projects to India";
               
               
                  $name = $_POST['name']; 
                  $email = $_POST['email'];
                  $phone = $_POST['phone']; 
                  $services = $_POST['services'];
                  $message = $_POST['message'];
               
               
               
               
                  $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 .= "Name: ".clean_string($name)."\n";
                  $email_message .= "Email: ".clean_string($email)."\n";
                  $email_message .= "Phone: ".clean_string($phone)."\n";
                  $email_message .= "Services: ".clean_string($services)."\n";
                  $email_message .= "Message: ".clean_string($message)."\n";
               
               
              // create email headers
              $headers = 'From: '.$email."\r\n".
              'Reply-To: '.$email."\r\n" .
              'X-Mailer: PHP/' . phpversion();
              ini_set("sendmail_from","impin@in.com"); 
              
              if (mail($email_to, $email_subject, $email_message, $headers))
              {
                  echo "<h4>Thank you for sending email</h4>";
              } else {
                echo "<h4>Can't send email</h4>";
              }
              
              }
              else {
              
              echo "<h3>Error</h3>";
              }
              ?>
              Emails coming from mail() scripts usually go to spam folder, be sure to check it if you're not receiving emails.

              Comment

              • impin
                New Member
                • Jul 2010
                • 127

                #8
                really this code works for you?!
                for me still not working..
                still i get result cant send mail...

                my web host provider provides
                php 4.3.2 only

                Comment

                • londres9b
                  New Member
                  • Apr 2010
                  • 106

                  #9
                  Oh.. I'm not sure if php 4.3.2 supports mail()..

                  Can't you get another provider that has php 5 ?

                  Comment

                  • impin
                    New Member
                    • Jul 2010
                    • 127

                    #10
                    ok thank you

                    Comment

                    • impin
                      New Member
                      • Jul 2010
                      • 127

                      #11
                      sorry. its php 4.2.3.

                      i will contact the web host provider.

                      Comment

                      • impin
                        New Member
                        • Jul 2010
                        • 127

                        #12
                        this code works for you. right?

                        Comment

                        • londres9b
                          New Member
                          • Apr 2010
                          • 106

                          #13
                          yes.. why? it isn't working for you?

                          Comment

                          • impin
                            New Member
                            • Jul 2010
                            • 127

                            #14
                            yes. its not working for me. i developed the script using php version 5.3.
                            i also tried in 4.2.3 version.

                            in both versions the mail function is not working. the web host provider provides php 4.2.3 version only.

                            Comment

                            • impin
                              New Member
                              • Jul 2010
                              • 127

                              #15
                              i get this error

                              Warning: Failed to connect to mailserver, verify your "SMTP" setting in php.ini in E:\Program Files\Ensim\WEB ppliance\SiteDa ta\Domains\outs ource projectstoindia .com\ROOT\Inetp ub\wwwroot\mail .php on line 11
                              Mail Not Sent.

                              Comment

                              Working...