Advertisement
Guest User

Untitled

a guest
Oct 12th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. $scope.submitContactForm = function() {
  2. $log.info($scope.contact);
  3. if ($scope.contactform.$valid) {
  4. $http({
  5. method : 'POST',
  6. url : 'http://blog.local/php/mail.php',
  7. data : $scope.contact, //forms user object
  8. headers : {'Content-Type': 'application/x-www-form-urlencoded'}
  9. })
  10. .success(function(data) {
  11. $log.info(data);
  12. if (data.errors) {
  13. // Showing errors.
  14. } else {
  15. $scope.messageForm = data.message;
  16. }
  17. });
  18. }
  19. };
  20.  
  21. <?php
  22. session_start();
  23. require_once('class.phpmailer.php');
  24. require_once('class.smtp.php');
  25. if($_POST) {
  26. if( !isset($_SESSION['sended']) ) {
  27. // Re-check with php
  28. if( isset( $_POST['name'] ) && !empty( $_POST['name'] ) ):
  29. $name = filter_var(trim($_POST['name']), FILTER_SANITIZE_STRING);
  30. else:
  31. echo $error = 'Name is empty!';
  32. return;
  33. endif;
  34.  
  35. if( isset( $_POST['contactlastname'] ) && !empty( $_POST['contactlastname'] ) ):
  36. $lastname = filter_var(trim($_POST['contactlastname']), FILTER_SANITIZE_STRING);
  37. // Add lastname to name
  38. $name = ($lastname) ? $name. ' ' .$lastname : $name;
  39. endif;
  40.  
  41. if( isset( $_POST['email'] ) && !empty( $_POST['email'] ) ):
  42. $email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
  43. if( !filter_var( $email , FILTER_VALIDATE_EMAIL ) ):
  44. echo $error = 'Email is not valid!';
  45. return;
  46. endif;
  47. else:
  48. echo $error = 'Email is empty!';
  49. return;
  50. endif;
  51.  
  52. if( isset( $_POST['subject'] ) && !empty( $_POST['subject'] ) ):
  53. $subject = filter_var(trim($_POST['subject']), FILTER_SANITIZE_STRING);
  54. else:
  55. $subject = "Hello";
  56. endif;
  57.  
  58. if( isset( $_POST['message'] ) && !empty( $_POST['message'] ) ):
  59. $message = filter_var(trim($_POST['message']), FILTER_SANITIZE_STRING);
  60. else:
  61. echo $error = 'Message is empty!';
  62. return;
  63. endif;
  64.  
  65. if(!isset($error)) {
  66. // if we have no validation errors prepare mail
  67. $mail = new PHPMailer;
  68. $mail->isSMTP();
  69. $mail->SMTPDebug = 0;
  70. $mail->Debugoutput = 'html';
  71.  
  72. //Set the hostname of the mail server gmail - yandex- outlook or your hosting's
  73. $mail->Host = "smtp.gmail.com"; // <------------ change with your host name
  74. // use
  75. // $mail->Host = gethostbyname('smtp.gmail.com');
  76. // if your network does not support SMTP over IPv6
  77.  
  78. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  79. $mail->Port = 465; // <------------ Change with port 25 - 465 - 587 and etc..
  80.  
  81. //Set the encryption system to use - ssl (deprecated) or tls
  82. $mail->SMTPSecure = 'ssl'; // <------------ tls (port 587) or ssl (port 465)
  83.  
  84. //Whether to use SMTP authentication
  85. $mail->SMTPAuth = true;
  86.  
  87. //Username to use for SMTP authentication - use full email address for gmail
  88. $mail->Username = "sharjilk62@gmail.com"; // <------------ Smtp authentication - username here
  89.  
  90. //Password to use for SMTP authentication
  91. $mail->Password = ""; // <------------ Smtp authentication -password here
  92.  
  93. $mail->setFrom($email, $name);
  94. $mail->AddReplyTo($email,$name);
  95.  
  96. //Set who the message is to be sent to --- CHANGE THIS EMAIL ADDDRES WITH THE ONE YOU WANT TO RECEIVE EMAILS AND WWIT YOUR NAME
  97. $mail->addAddress('sharjilk62@gmail.com', 'Sharjil'); // <----------- CHANGE YOUR WITH YOUR EMAIL ADDRES
  98.  
  99. $mail->Subject = $subject;
  100. $mail->msgHTML($message);
  101.  
  102. // If send me copy checkbox is checked send a copy to user
  103. if( isset( $_POST['contactselfemail'] ) ):
  104. $mail->addCC($email);
  105. endif;
  106.  
  107. // Send mail and report the result
  108. if($mail->send()):
  109. echo 'success';
  110. $_SESSION['sended'] = 'sended';
  111. else:
  112. echo 'error';
  113. unset( $_SESSION['sended'] );
  114. endif;
  115. }
  116. } else {
  117. echo 'already';
  118. }
  119. }
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement