Nikita

Nikita

  • NA
  • 56
  • 10.3k

how to send date and multiple selected values to email using

Feb 26 2020 12:39 AM
php mail() function?
1)appointment.html
  1. <section id="service-single-area">  
  2. <div class="container">  
  3. <div class="row">  
  4. <div class="col-lg-9 col-md-8 col-sm-12 col-xs-12 pull-right">  
  5. <div class="service-single-content">  
  6. <div class="appoinment-form">  
  7. <div class="title">  
  8. <h2>Make an Appoinment</h2>  
  9. </div>  
  10. <form id="appoinmentone" name="appointment" action="sendmail.php" method="post" enctype="text/plain" >  
  11. <div class="row">  
  12. <div class="col-md-6">  
  13. <input type="text" name="name" value="" placeholder="Your Name*"  
  14. required="" >  
  15. <input type="email" name="email" value="" placeholder="Your Mail*"  
  16. required="" >  
  17. <input type="text" name="mobile" value="" placeholder="Phone Number*"  
  18. required="" >  
  19. <input type="date" name="date" value="" placeholder="Apointment Date*"  
  20. required="">  
  21.   
  22. </div>  
  23. <div class="col-md-6">  
  24. <select class="selectmenu" name="service[]" multiple="multiple">  
  25. <option selected="selected">Select Service</option>  
  26. <option>Commercial Aquaguard</option>  
  27. <option>Industrial RO Plants</option>  
  28. <option>Water Cooler</option>  
  29. <option>Commercial Vacuum Cleaner</option>  
  30. <option>Water Ionizers</option>  
  31. </select>  
  32. <textarea name="message" placeholder="Your Message.."  
  33. required="" ></textarea>  
  34. </div>  
  35. </div>  
  36. <div class="row">  
  37. <div class="col-md-12">  
  38. <form method="post" >  
  39. <a href="#" class="contact-btn" onclick="document.getElementById('appoinmentone').submit()">Send</a>  
  40. </form>  
  41. </div>  
  42. </div>  
  43. </form>  
  44. </div>  
  45.   
  46. </div>  
  47. </div>  
  48. </div>  
  49. </div>  
  50. </section>  
2)sendmail.php
  1. <?php  
  2. if (isset($_POST['email']))  
  3. {  
  4. // EDIT THE 2 LINES BELOW AS REQUIRED  
  5. $email_to = "[email protected]";  
  6. $email_subject = "Appointment Received";  
  7. function died($error)  
  8. {  
  9. // your error code can go here  
  10. echo "We are very sorry, but there were error(s) found with the form you submitted. ";  
  11. echo "These errors appear below.<br /><br />";  
  12. echo $error . "<br /><br />";  
  13. echo "Please go back and fix these errors.<br /><br />";  
  14. die();  
  15. }  
  16. // validation expected data exists  
  17. if (!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['mobile']) || !isset($_POST['date'])|| !isset($_POST['service'])|| !isset($_POST['message']))  
  18. {  
  19. died('We are sorry, but there appears to be a problem with the form you submitted.');  
  20. }  
  21. $name = $_POST['name']; // required  
  22. $email_from = $_POST['email']; // required  
  23. $mobile = $_POST['mobile']; // not required  
  24. $date = $_POST['date']; // required  
  25. $service = $_POST['service']; // required  
  26. $message = $_POST['message']; // required  
  27. $error_message = "";  
  28. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';  
  29. if (!preg_match($email_exp$email_from))  
  30. {  
  31. $error_message .= 'The Email Address you entered does not appear to be valid.<br />';  
  32. }  
  33. $string_exp = "/^[A-Za-z .'-]+$/";  
  34. if (!preg_match($string_exp$name))  
  35. {  
  36. $error_message .= 'The First Name you entered does not appear to be valid.<br />';  
  37. }  
  38. if (strlen($mobile) < 11)  
  39. {  
  40. $error_message .= 'The mobile number you entered do not appear to be valid.<br />';  
  41. }  
  42. if (strlen($error_message) > 0)  
  43. {  
  44. died($error_message);  
  45. }  
  46. $email_message = "Form details below.\n\n";  
  47. function clean_string($string)  
  48. {  
  49. $bad = array(  
  50. "content-type",  
  51. "bcc:",  
  52. "to:",  
  53. "cc:",  
  54. "href"  
  55. );  
  56. return str_replace($bad""$string);  
  57. }  
  58. $email_message .= "First Name: " . clean_string($name) . "\n";  
  59. $email_message .= "Email: " . clean_string($email_from) . "\n";  
  60. $email_message .= "Mobile: " . clean_string($mobile) . "\n";  
  61. $email_message .= "Date: " . clean_string($date) . "\n";  
  62. $email_message .= "Services: " . clean_string($service) . "\n";  
  63. $email_message .= "Message: " . clean_string($message) . "\n";  
  64. $body = "Mail Send";  
  65. $msg = 'Name:-' . $_POST['name'] . "\n" . 'Email:-' . $_POST['email'] . "\n" . 'Mobile:-' . $_POST['mobile'] . "\n" . 'Date:-' . $_POST['date'] . "\n" . 'Services:-' . $_POST['service'] . "\n" . 'Message:-' . $_POST['message'];  
  66. mail($email_to$email_subject$msg);  
  67. // echo "Your E-mail has been sent !Thank you for contacting us. We will be in touch with you very soon.";  
  68. if($send_mail)  
  69. {  
  70. echo "Your E-mail has been sent !Thank you for contacting us. We will be in touch with you very soon.";  
  71. }  
  72. else  
  73. {  
  74. echo "E-mail sent was failed !";  
  75. }  
  76. ?>  
  77. <!--include your own success html here-->  
  78.   
  79. <?php  
  80. }  
  81. ?>  
please suggest me the solution for above problem. here i want to pass date and selected values to email along with other details