Connect with Expertise | Find Experts, Get Answers, Share Insights

Form data to email

 
Join Date: Apr 2009
Posts: 11
#1: Jan 31 '10
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
Expand|Select|Wrap|Line Numbers
  1.     <form action="enquiry.php" method="POST" name="form" id="form" onSubmit="return valid_form()" target="_self">
  2.  <input type="hidden" name="success_page" value="enquiry.html" />
  3. ................
  4. .............
  5. .......
  6. <input name="submit" value="Submit Enquiry" type="submit"
  7. </form>
Please help.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $nature=$_POST['nature'];
  3. $enquiry=$_POST['enquiry'];
  4. $quantity=$_POST['quantity'];
  5. $company=$_POST['company'];
  6. $name=$_POST['name'];
  7. $email=$_POST['email'];
  8. $phone_country_code=$_POST['phone_country_code'];
  9. $phone_area_code=$_POST['phone_area_code'];
  10. $phone=$_POST['phone'];
  11. $fax=$_POST['fax'];
  12. $addr=$_POST['addr'];
  13. $city=$_POST['city'];
  14. $code=$_POST['code'];
  15. $country=$_POST['country'];
  16.  
  17.  
  18. # Email to Form Owner
  19.  
  20. $emailSubject = "Online Enquiry";
  21.  
  22. $emailBody = "Nature of Business:$nature\n"
  23.  . "Requirement : $enquiry\n"
  24.  . "Quantity : $quantity\n"
  25.  . "Company name : $company\n"
  26.  . "Name : $name\n"
  27.  . "Email : $email\n"
  28.  . "Country Code : $phone_country_code\n"
  29.  . "Area Code : $phone_area_code\n"
  30.  . "Phone : $phone\n"
  31.  . "Fax : $fax\n"
  32.  . "Address : $addr\n"
  33.  . "City : $city\n"
  34.  . "Zip code : $code\n"
  35.  . "Country Name: $country\n"
  36.  . "";
  37.  
  38.  $emailTo ="user1@example.com";
  39.  $emailFrom="Enquiry";
  40.  $emailHeader = "From: $emailFrom\n"
  41.   . "MIME-Version: 1.0\n"
  42.   . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
  43.   . "Content-transfer-encoding: 7bit\n";
  44.  
  45. mail($emailTo, $emailSubject, $emailBody, $emailHeader);
  46. header("Location: enquiry.html"); 
  47.  
  48.  //include("coupon.php");
  49. $successpage=$_POST{"success_page"};
  50. ?>

realin's Avatar
C
 
Join Date: Feb 2007
Location: India
Posts: 254
#2: Jan 31 '10

re: Form data to email


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.
kovik's Avatar
E
C
 
Join Date: Jun 2007
Location: Baltimore
Posts: 905
#3: Jan 31 '10

re: Form data to email


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.
Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,372
#4: Jan 31 '10

re: Form data to email


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.
Reply