Guest User

form

a guest
Mar 28th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. <?php
  2.  
  3. /*error_reporting(E_ALL);
  4. ini_set("display_errors", 1);
  5. */
  6. require_once 'vendor/autoload.php';
  7. /**
  8. * Simple contact file for sending emails
  9. */
  10. header("Content-Type: application/json");
  11. if (isset($_POST) && count($_POST) > 0) {
  12. $name = '';
  13. $email = '';
  14. $phone = '';
  15. $company = '';
  16. $designation = '';
  17. $billing_name = '';
  18. $billing_email = '';
  19. $billing_phone = '';
  20. $billing_company = '';
  21. $address_line1 = '';
  22. $address_line2 = '';
  23. $city = '';
  24. $state = '';
  25. $country = '';
  26. $pincode = '';
  27.  
  28. $isValid = true;
  29. if (empty($_POST['form_name']) or empty($_POST['form_email']) or empty($_POST['form_phone'])
  30. or empty($_POST['form_company']) or empty($_POST['billing_name']) or empty($_POST['billing_email']) or empty($_POST['billing_phone']) or empty($_POST['billing_company'])) {
  31. $isValid = false;
  32. }
  33.  
  34. function test_input($data) {
  35. $data = trim($data);
  36. $data = stripslashes($data);
  37. $data = htmlspecialchars($data);
  38. return $data;
  39. }
  40.  
  41. if ($isValid) {
  42. $name = test_input($_POST['form_name']);
  43. $email = test_input($_POST['form_email']);
  44. $phone = test_input($_POST['form_phone']);
  45. $company = test_input($_POST['form_company']);
  46. $designation = test_input($_POST['form_designation']);
  47. $billing_name = test_input($_POST['billing_name']);
  48. $billing_email = test_input($_POST['billing_email']);
  49. $billing_phone = test_input($_POST['billing_phone']);
  50. $billing_company = test_input($_POST['billing_company']);
  51. $address_line1 = test_input($_POST['address_line1']);
  52. $address_line2 = test_input($_POST['address_line2']);
  53. $city = test_input($_POST['city']);
  54. $state = test_input($_POST['state']);
  55. $country = test_input($_POST['country']);
  56. $pincode = test_input($_POST['pincode']);
  57.  
  58. $mail = new PHPMailer;
  59.  
  60.  
  61.  
  62. $mail->isSMTP(); // Set mailer to use SMTP
  63. $mail->SMTPOptions = [
  64. 'ssl' => [
  65. 'verify_peer' => false,
  66. 'verify_peer_name' => false,
  67. 'allow_self_signed' => true,
  68. ],
  69. ];
  70. $mail->Host = 'mail.lyotalk.com'; // Specify main and backup SMTP servers
  71. $mail->SMTPAuth = true; // Enable SMTP authentication
  72. $mail->Username = 'web@lyotalk.com'; // SMTP username
  73. $mail->Password = 'lyotalk@123'; // SMTP password
  74. $mail->SMTPSecure = ''; // Enable TLS encryption, `ssl` also accepted
  75. $mail->Port = 587;
  76. $mail->setFrom('web@lyotalk.com', 'Lyotalk Ireland 2017');
  77. $mail->addAddress('web@biotrains.com.test-google-a.com', 'Lyotalk Ireland 2017'); // Add a recipient
  78. //var_dump($_FILES);die();
  79.  
  80. $mail->isHTML(true);
  81.  
  82. $mail->Subject = "Registration of Lyotalk Ireland - 2017";
  83. $body = 'Hi I am '.$name.' and have mailed for '.$mail->Subject.'.<br>
  84. <b>Delegate Details : </b>
  85. Name : '.$name.'<br>
  86. Email : '.$email.'<br>
  87. Phone : '.$phone.'<br>
  88. Company : '.$company.'<br>
  89. Designation : '.$designation.'<br>
  90. <b>Billing Details : </b>
  91. Billing Name : '.$billing_name.'<br>
  92. Billing Email : '.$billing_email.'<br>
  93. Billing Phone : '.$billing_phone.'<br>
  94. Billing Company : '.$billing_company.'<br>
  95. Address Line 1 : '.$address_line1.'<br>
  96. Address Line 2 : '.$address_line2.'<br>
  97. City : '.$city.'<br>
  98. State : '.$state.'<br>
  99. Country : '.$country. '<br>
  100. Pincode : '.$pincode;
  101.  
  102. $mail->Body = nl2br($body);
  103.  
  104. $msg = ["msg" => "Email sent successfully!"];
  105. if (!$mail->send()) {
  106. $msg["msg"] = "Failed to send email - " . $mail->ErrorInfo;
  107. }
  108. header("Location: http://www.lyotalk.com/"); /* Redirect browser */
  109.  
  110. } else {
  111. echo json_encode(["msg" => "Some fields are missing!"]);
  112. }
  113. } else {
  114. echo json_encode(["msg" => "Somethings wrong!"]);
  115. }
  116.  
  117. ?>
Add Comment
Please, Sign In to add comment