Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. require "PHPMailer/PHPMailerAutoload.php";
  2.  
  3. $data = array();
  4. $data['error'] = 1;
  5. $data['msg'] = '';
  6. if(isset($_POST)){
  7. if(!empty($_POST)){
  8. $name = '';
  9. if(isset($_POST['name'])){
  10. $name = $_POST['name'];
  11. }
  12. $email = '';
  13. if(isset($_POST['email'])){
  14. $email = $_POST['email'];
  15. }
  16. $subject = '';
  17. if(isset($_POST['subject'])){
  18. $subject = $_POST['subject'];
  19. }
  20. $message = '';
  21. if(isset($_POST['message'])){
  22. $message = $_POST['message'];
  23. }
  24. $mailsubject = variable_get('site_name').' - '.'Contact Me';
  25. $emailTo = variable_get('contact_mail');
  26. $tpl = file_get_contents(drupal_get_path('module', 'elsayed').'/emails/contactus.html');
  27. $html_message = str_replace(array('{{mailsubject}}', '{{name}}', '{{email}}', '{{subject}}', '{{message}}'),
  28. array($mailsubject, $name, $email, $subject, $message), $tpl);
  29. if($emailTo != ''){
  30. $mail = new PHPMailer();
  31. $mail->IsSMTP();
  32. $mail->SMTPAuth = true;
  33. $mail->CharSet = "UTF-8";
  34. //$mail->SMTPSecure = 'tls';
  35. $mail->Host = getenv('MAIL_HOST');
  36. $mail->Port = getenv('MAIL_PORT');
  37. $mail->Username = getenv('MAIL_USERNAME');
  38. $mail->Password = getenv('MAIL_PASSWORD');
  39. $mail->From = $email;
  40. $mail->FromName = $name;
  41. $mail->addAddress($emailTo, variable_get('site_name'));
  42. $mail->isHTML(true);
  43. $mail->Subject = $mailsubject;
  44. $mail->Body = $html_message;
  45. $mail->AltBody = "This is the plain text version of the email content";
  46.  
  47. if ($mail->send()) {
  48. //$data['msg'] = __('Thank you for your message. We will get back to you the soonest.');
  49. $data['error'] = 0;
  50. }else{
  51. //$data['msg'] = __('There was a problem sending the Email. Please try again.');
  52. $data['error'] = 1;
  53. }
  54. }else{
  55. //$data['msg'] = __('There was a problem sending the Email. Please try again.');
  56. $data['error'] = 1;
  57. }
  58.  
  59. }
  60. }
  61. echo json_decode($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement