Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. app.controller('ContactController', function ($scope, $http) {
  2. $scope.result = 'hidden'
  3. $scope.resultMessage;
  4. $scope.formData; //formData is an object holding the name, email, subject, and message
  5. $scope.submitButtonDisabled = false;
  6. $scope.submitted = false;
  7. $scope.submit = function(contactform) {
  8. $scope.submitted = true;
  9. $scope.submitButtonDisabled = true;
  10. if (contactform.$valid) {
  11. var request = $http({
  12. method : 'POST',
  13. url : 'php/contact.php',
  14. data : $.param($scope.formData), //param method from jQuery
  15. headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
  16. });
  17. if (request.success) {
  18. console.log(request);
  19. $scope.submitButtonDisabled = false;
  20. $scope.result='bg-success';
  21. $scope.resultMessage = request.message;
  22. } else {
  23. $scope.submitButtonDisabled = true;
  24. $scope.resultMessage = request.message;
  25. //$scope.resultMessage = "Opps!... something went wrong. Please Contact OpenHouse directly to let them know of this error.";
  26. $scope.result='bg-danger';
  27. };
  28. //};
  29. } else {
  30. $scope.submitButtonDisabled = false;
  31. $scope.resultMessage = 'Failed <img src="http://www.chaosm.net/blog/wp-includes/images/smilies/icon_sad.gif" alt=":(" class="wp-smiley"> Please fill out all the fields.';
  32. $scope.result='bg-danger';
  33. }
  34. }
  35. });
  36.  
  37. <?php
  38.  
  39. require_once ("class.phpmailer.php"); // Include phpmailer class
  40. ini_set('display_errors', 'On');
  41. error_reporting(E_ALL | E_STRICT);
  42.  
  43. if (isset($_POST['inputFirstName']) && isset($_POST['inputLastName']) && isset($_POST['inputEmail']) && isset($_POST['inputPhone']) && isset($_POST['inputMessage'])) {
  44.  
  45. //check if any of the inputs are empty
  46. if (empty($_POST['inputFirstName']) || empty($_POST['inputLastName']) || empty($_POST['inputEmail']) || empty($_POST['inputPhone']) || empty($_POST['inputMessage'])) {
  47. $data = array('success' => false, 'message' => 'Please fill out the form completely.');
  48. echo json_encode($data);
  49. exit;
  50. }
  51.  
  52. $message=
  53. 'First Name: '.$_POST['inputFirstName'].'<br />
  54. Last Name: '.$_POST['inputLastName'].'<br />
  55. Phone: '.$_POST['inputPhone'].'<br />
  56. Email: '.$_POST['inputEmail'].'<br />
  57. Comments: '.$_POST['inputMessage'].'
  58. ';
  59.  
  60. $mail = new PHPMailer(); // Instantiate the PHPMailer Class
  61. $mail->IsSMTP(); // enable SMTP
  62. $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
  63. $mail->SMTPAuth = true; // SMTP authentication enabled
  64. $mail->SMTPSecure = 'ssl'; // secure transfer enabled + REQUIRED for Gmail (either SSL or TLS)
  65. $mail->Host = "smtp.gmail.com"; //Gmail SMTP Server to relay thru
  66. $mail->Port = 465; // Port 465 as we're using SSL... or use Port 587 for TLS
  67. $mail->IsHTML(true); // We're sending a HTML formatted message
  68. $mail->Username = "....@gmail.com"; // Gmail account for authentication
  69. $mail->Password = "*********"; // Gmail password for authentication
  70. $mail->SetFrom("....@gmail.com"); // The email is being sent from this address
  71. $mail->Subject = "Website Contact Form Enquiry"; // The subject line of the email
  72. $mail->Body = ($message); // The actual email message to be sent
  73. $mail->AddAddress("....@gmail.com"); // The email is being sent to this address
  74.  
  75. if(!$mail->send()) {
  76. echo json_encode(['success' => false, 'message' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo]);
  77. exit;
  78. }
  79.  
  80. error_log("Data: ".$data['success']." Message: ".$data['message']);
  81. echo json_encode(['success' => true, 'message' => 'Thanks! We have received your message.']);
  82.  
  83. } else {
  84. echo json_encode(['success' => false, 'message' => 'Please fill out the form completely.']);
  85. }
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement