Form data to email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PrabodhanP
    New Member
    • Apr 2009
    • 14

    Form data to email

    I have following php file which I am placing as a form action,the coding seems right as i get all variables value when I echo the statements,but I dont know what happen to this,I am not getting this to email-id. Also my form tag is like
    Code:
        <form action="enquiry.php" method="POST" name="form" id="form" onSubmit="return valid_form()" target="_self">
     <input type="hidden" name="success_page" value="enquiry.html" />
    ................
    .............
    .......
    <input name="submit" value="Submit Enquiry" type="submit"
    </form>
    Please help.

    Code:
    <?php
    $nature=$_POST['nature'];
    $enquiry=$_POST['enquiry'];
    $quantity=$_POST['quantity'];
    $company=$_POST['company'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $phone_country_code=$_POST['phone_country_code'];
    $phone_area_code=$_POST['phone_area_code'];
    $phone=$_POST['phone'];
    $fax=$_POST['fax'];
    $addr=$_POST['addr'];
    $city=$_POST['city'];
    $code=$_POST['code'];
    $country=$_POST['country'];
    
    
    # Email to Form Owner
    
    $emailSubject = "Online Enquiry";
    
    $emailBody = "Nature of Business:$nature\n"
     . "Requirement : $enquiry\n"
     . "Quantity : $quantity\n"
     . "Company name : $company\n"
     . "Name : $name\n"
     . "Email : $email\n"
     . "Country Code : $phone_country_code\n"
     . "Area Code : $phone_area_code\n"
     . "Phone : $phone\n"
     . "Fax : $fax\n"
     . "Address : $addr\n"
     . "City : $city\n"
     . "Zip code : $code\n"
     . "Country Name: $country\n"
     . "";
    
     $emailTo ="user1@example.com";
     $emailFrom="Enquiry";
     $emailHeader = "From: $emailFrom\n"
      . "MIME-Version: 1.0\n"
      . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
      . "Content-transfer-encoding: 7bit\n";
      
    mail($emailTo, $emailSubject, $emailBody, $emailHeader);
    header("Location: enquiry.html"); 
    
     //include("coupon.php");
    $successpage=$_POST{"success_page"};
    ?>
    Last edited by Atli; Jan 31 '10, 04:04 PM. Reason: Please use [code] tags when posting code... And don't include real email addresses in your code.
  • realin
    Contributor
    • Feb 2007
    • 254

    #2
    What server are you using, are you trying to send email from localhost.
    Just a note remove your email address from the above code. You might get lotsa spam emails.

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      The mail() function only works if the server knows what e-mail to send from and what SMTP server to use for sending. As ~realin suggested, if you are trying to do this from localhost, you likely haven't set up these variables. Otherwise, it's a matter of whether your host has set them up for you. I'd suggest using a more capable mailing library for PHP like SwiftMailer.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        The mail() function only works if the server knows what e-mail to send from and what SMTP server to use for sending.
        that’s true for the windows implementation of mail(). the unix implementation uses the local sendmail programme.

        Comment

        Working...