Advertisement
Guest User

Send_contact_form.php

a guest
Feb 12th, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. <?php
  2. // Set correct timezone
  3. date_default_timezone_set('Europe/Helsinki');
  4.  
  5. $timezone = date_default_timezone_get();
  6. $date = date('d.m.Y H:i', time());
  7.  
  8.  
  9. $data = json_decode(file_get_contents('php://input'), true);
  10.  
  11. if ($data) {
  12. $contact_message = $data["message"];
  13. $contact_name = $data["name"];
  14. $contact_phone = $data["phone"];
  15. $contact_email = $data["email"];
  16. $email_is_valid = filter_var($contact_email, FILTER_VALIDATE_EMAIL);
  17.  
  18. if ($email_is_valid) {
  19. // Send email to drivers
  20. $to = 'teemuvikstrom@gmail.com';
  21. $subject = 'Yhteydenottolomake ' . $date;
  22.  
  23. $message = "
  24. Yhteydenottolomake specialtaxitalja.fi:stä:
  25.  
  26. Nimi: " . $contact_name . "
  27. Puhelin: " . $contact_phone . "
  28. Email: " . $contact_email . "
  29. Viesti:
  30.  
  31. " . $contact_message . "
  32.  
  33.  
  34. Viesti lähetetty: " . $date . "
  35. Vierailijan IP: " . $_SERVER["REMOTE_ADDR"];
  36.  
  37. $headers = 'From: teemuvikstrom@gmail.com' . "\r\n" .
  38. 'Reply-To: teemuvikstrom@gmail.com' . "\r\n" .
  39. 'X-Mailer: PHP/' . phpversion();
  40.  
  41. $mail_sending_result = mail($to, $subject, $message, $headers);
  42.  
  43. // Return success message
  44. http_response_code(200);
  45. header('Content-Type: application/json');
  46. echo '{ "success": true, "response": "' . $mail_sending_result . '" }';
  47. } else {
  48. http_response_code(400);
  49. header('Content-Type: application/json');
  50. echo '{ "success": false, "detail": "Sähköposti ei kelpaa!" }';
  51. }
  52. } else {
  53. http_response_code(400);
  54. header('Content-Type: application/json');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement