Send form inputs to email address

Reply

Join Date: Apr 2007
Posts: 4
Reputation: Legend01 is an unknown quantity at this point 
Solved Threads: 0
Legend01 Legend01 is offline Offline
Newbie Poster

Send form inputs to email address

 
0
  #1
Apr 12th, 2007
hi there, i have created a php website for my mobile DJ business, and want a booking enquiry form so people can fill out their details and email the data to us and we can then contact them about their booking.
I have created the form in html, and using an index.php file and the include code to load the html form in the page. you can view the file at:
http://voguefm.co.uk/xfaders/site/mo...e=Booking_Form
it is an inactive module at the moment.
basically i have experimented with using a sendmail.php file but i dont really have enough knowledge of php to get it to work properly.
I have created a script that sends me an email with the correct subject title but with no content in the main message of the email.
can anyone help me create a sendmail.php file that will send all of the data in the form? is it even possible? as it uses tick boxes and drop down menu's.

hopefully that can be understood by someone!
thanks for your help
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 57
Reputation: GliderPilot is an unknown quantity at this point 
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: Send form inputs to email address

 
0
  #2
Apr 12th, 2007
Your php page that you use after the form is submitted would have to check all the check boxes to to see if they are checked:

  1. if(isset($_POST['checkboxname']))
  2. {
  3.  
  4. $somevalue = "yes";
  5.  
  6. }
  7. else
  8. {
  9.  
  10. $somevalue = "no";
  11.  
  12. }

Personally I would load all the form variables into variables to make things easier to manage and look at.

At this point you would create the actual mail script including all the info you need.

The basic setup to send mail is as follows:

mail(e-mail address to send to,subject,body,from)

Usualy this is put in an if statement just for error purposes if it does not work.

Here is an example contact us form that I have available for download on my site.

  1.  
  2. <?
  3. ////////////////////////////////////////////////////////
  4. //
  5. // THIS CODE WAS CREATED BY ETYN.COM
  6. // YOU MAY USE THIS CODE FOR FREE
  7. // BUT THIS MESSAGE MUST STAY INTACT
  8. //
  9. ///////////////////////////////////////////////////////
  10.  
  11. $formgood = true;
  12. $name = $_POST['name'];
  13. $email = $_POST['email'];
  14. $comments = $_POST['comments'];
  15. $to = "<a href="mailto:user@mail.com">user@mail.com</a>"; //Please change this to your e-mail address
  16. $message = "$name has submitted a contact form. \n\n $comments \n\n You can reply to $email";
  17. //check to make sure all form elements were filled in
  18. if ($name == "") {
  19. echo 'You must provide your name to contact us. Please click the back, and try again';
  20. $formgood = false;
  21. }
  22. if ($email == "") {
  23. echo 'We require an e-mail address in order for us to respond. Please go back and try again.';
  24. $formgood = false;
  25. }
  26. if ($comments == "") {
  27. echo 'You must provide comments in order to submit this form. Please click back, and try again.';
  28. $formgood = false;
  29. }
  30. if ($formgood) {
  31. if(mail($to, "A contact us form has been submitted by $name", $message, "From: $email\n")) {
  32. echo 'Thank you for submitting this form. We will review your comments and contact you shortly. <br><br> Copyright ' . date(Y) . ' ETYN Corps. All rights reserved.';
  33. }
  34. else
  35. {
  36. echo "An error has occured. Please contact the webmaster.";
  37. }
  38. }
  39. else {
  40.  
  41. echo "<br> Please review the comments above and try again.";
  42.  
  43. echo '<br>Copyright ' . date(Y) . ' ETYN Corps. All rights reserved.';
  44. }
  45. ?>
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 4
Reputation: Legend01 is an unknown quantity at this point 
Solved Threads: 0
Legend01 Legend01 is offline Offline
Newbie Poster

Re: Send form inputs to email address

 
0
  #3
Apr 12th, 2007
that script works fine, thank you very much!
so if i wanted to add a field for a telephone number i would create the field in the html page. naming is 'telephone'
and in the PHP script it would look like this:
  1. <?
  2. ////////////////////////////////////////////////////////
  3. //
  4. $formgood = "t";
  5. $telephone = $_POST['telephone'];
  6. $name = $_POST['name'];
  7. $email = $_POST['email'];
  8. $comments = $_POST['comments'];
  9. $to = "<a href="mailto:thex-faders@fsmail.net">thex-faders@fsmail.net</a>"; //Please change this to your e-mail address
  10. $message = "$name has submitted a contact form. \n\n $comments \n\n You can reply to $email";
  11. //check to make sure all form elements were filled in
  12. if ($name == "") {
  13. echo 'You must provide your name to contact us. Please click the back, and try again';
  14. $formgood = "f";
  15. }
  16. if ($email == "") {
  17. echo 'We require an e-mail address in order for us to respond. Please go back and try again.';
  18. $formgood = "f";
  19. }
  20. if ($comments == "") {
  21. echo 'You must provide comments in order to submit this form. Please click back, and try again.';
  22. $formgood = "f";
  23. }
  24. if ($telephone == "") {
  25. echo 'You must provide comments in order to submit this form. Please click back, and try again.';
  26. $formgood = "f";
  27. }
  28. if ($formgood == "t") {
  29. if(mail($to, "A contact us form has been submitted by $name", $message, $telephone, "From: $email\n")) {
  30. echo 'Thank you for submitting this form. We will review your comments and contact you shortly. <br><br> Copyright ' . date(Y) . ' ETYN Corps. All rights reserved.';
  31. }
  32. }
  33. else {
  34.  
  35. echo '<br>Copyright ' . date(Y) . ' ETYN Corps. All rights reserved.';
  36. }
  37. ?>
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 57
Reputation: GliderPilot is an unknown quantity at this point 
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: Send form inputs to email address

 
0
  #4
Apr 12th, 2007
Not quite you don't place the telephone variable after the message variable you place it in the message variable. So the actual mail statement would not change. Your $message line at the beggining would change to something like this:

$message = "$name has submitted a contact form. \n\n $comments \n\n You can reply to $email \n Telephone: $telephone";
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC