Advertisement
Guest User

Untitled

a guest
Jul 13th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.74 KB | None | 0 0
  1. ( ! ) Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:wamp64wwwcontact_formcontact.php on line 50
  2. Call Stack
  3. # Time Memory Function Location
  4. 1 0.0005 262960 {main}( ) ...contact.php:0
  5. 2 0.0006 267424 mail ( ) ...contact.php:50
  6. Contact form successfully submitted. Thank you, I will get back to you soon!You are a robot202Array ( [0] => HTTP/1.1 202 Accepted [1] => Server: nginx [2] => Date: Thu, 13 Jul 2017 15:28:17 GMT [3] => Content-Type: text/plain; charset=utf-8 [4] => Content-Length: 0 [5] => Connection: keep-alive [6] => X-Message-Id: M3h94F6oT8S5dfT9Q2IwGQ [7] => X-Frame-Options: DENY [8] => Access-Control-Allow-Origin: https://sendgrid.api-docs.io [9] => Access-Control-Allow-Methods: POST [10] => Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl [11] => Access-Control-Max-Age: 600 [12] => X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html [13] => [14] => )
  7.  
  8. echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
  9. echo "sendgrid.env" >> .gitignore
  10. source ./sendgrid.env
  11.  
  12. **index.php**
  13. <!DOCTYPE html>
  14. <html lang="en">
  15. <head>
  16. <meta charset="utf-8">
  17. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  18. <meta name="viewport" content="width=device-width, initial-scale=1">
  19. <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  20. <title>Contact Form</title>
  21.  
  22. <!-- Bootstrap -->
  23. <link href="css/bootstrap.min.css" rel="stylesheet">
  24.  
  25.  
  26. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  27. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  28. <!--[if lt IE 9]>
  29. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  30. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  31. <![endif]-->
  32. </head>
  33. <body>
  34.  
  35. <div class="container">
  36. <div class="row">
  37. <div class="col-md-12">
  38. <div class="row">
  39. <h2 class="contact-title">Contact US</h2>
  40. </div>
  41. </div>
  42.  
  43. <span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span>
  44. <div class="row">
  45. <div class="col-md-6">
  46. <p>University</p>
  47. </div>
  48. </div>
  49.  
  50. <span class="glyphicon glyphicon-earphone" aria-hidden="true"></span>
  51. <div class="row">
  52. <div class="col-md-6">
  53. <p>+81 (0)3 54</p>
  54. </div>
  55. </div>
  56.  
  57. <div class="row" style="border: solid 1px #000000;"></div>
  58. <div class="col-md-12">
  59. <div class="row">
  60. <h2 class="contact-title">Get In Touch</h2>
  61. </div>
  62. </div>
  63.  
  64. <form id="contact-form" method="post" action="contact.php" role="form">
  65. <div class="messages"></div>
  66. <div class="controls">
  67. <div class="row">
  68. <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
  69. <div class="form-group">
  70. <label for="form_name">Name *</label>
  71. <input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your name" required="required" data-error="Name is required.">
  72. <div class="help-block with-errors"></div>
  73. </div>
  74. </div>
  75. </div>
  76.  
  77. <div class="row">
  78. <div class="col-md-6">
  79. <div class="form-group">
  80. <label for="form_email">Email *</label>
  81. <input id="form_email" type="email" name="email" class="form-control" placeholder="example@domain.com " required="required" data-error="Valid email is required.">
  82. <div class="help-block with-errors"></div>
  83. </div>
  84. </div>
  85. </div>
  86.  
  87. <div class="row">
  88. <div class="col-md-6">
  89. <div class="form-group">
  90. <label for="form_phone">Phone</label>
  91. <input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
  92. <div class="help-block with-errors"></div>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97.  
  98.  
  99. <div class="row">
  100. <div class="col-md-6">
  101. <div class="form-group">
  102. <label for="form_subject">Subject *</label>
  103. <textarea id="form_subject" name="subject" class="form-control" placeholder="Subject " rows="4" required="required" data-error="Enter Subject"></textarea>
  104. <div class="help-block with-errors"></div>
  105. </div>
  106. </div>
  107. </div>
  108.  
  109. <div class="row">
  110. <div class="col-md-6">
  111. <div class="form-group">
  112. <label for="form_message">Message *</label>
  113. <textarea id="form_message" name="message" class="form-control" placeholder="Message for me " rows="4" required="required" data-error="Please,leave us a message."></textarea>
  114. <div class="help-block with-errors"></div>
  115. </div>
  116. </div>
  117. </div>
  118.  
  119.  
  120.  
  121. <div class="row">
  122. <div class="col-md-6">
  123. <div class="form-group">
  124. <label class="control-label">Captcha:</label>
  125. <div class="g-recaptcha" data-sitekey="6LfK7ygUAAAAAAKW"></div>
  126. </div>
  127. </div>
  128. </div>
  129.  
  130. <div class="row">
  131. <div class="col-md-12">
  132. <input type="submit" class="btn btn-success btn-send" value="Send message">
  133. </div>
  134. </div>
  135. </div>
  136.  
  137. <div class="row">
  138. <div class="col-md-12">
  139. <p class="text-muted"><strong>*</strong> These fields are required. </p>
  140. </div>
  141. </div>
  142. </div>
  143.  
  144. </form>
  145.  
  146. <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  147. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  148. <!-- Include all compiled plugins (below), or include individual files as needed -->
  149. <script src="js/bootstrap.min.js"></script>
  150. <script src="contact.js"></script>
  151. <script src="https://www.google.com/recaptcha/api.js"></script>
  152.  
  153. </body>
  154. </html>
  155.  
  156.  
  157. **contact.php**
  158.  
  159. <?php
  160.  
  161. // an email address that will be in the From field of the email.
  162. $from = 'Demo contact form <demo@gmail.com >';
  163.  
  164. // an email address that will receive the email with the output of the form
  165. $to = 'Demo contact form <test@gmail.com>';
  166.  
  167. // subject of the email
  168. $subject = 'New Message Recieved';
  169.  
  170. // form field names and their translations.
  171. // array variable name => Text to appear in the email
  172. $fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message');
  173.  
  174. // message that will be displayed when everything is OK :)
  175. $okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
  176.  
  177. // If something goes wrong, we will display this message.
  178. $errorMessage = 'There was an error while submitting the form. Please try again later';
  179.  
  180. /*
  181. * LET'S DO THE SENDING
  182. */
  183.  
  184. // if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
  185. error_reporting(E_ALL & ~E_NOTICE);
  186.  
  187. try
  188. {
  189. if(count($_POST) == 0) throw new Exception('Form is empty');
  190.  
  191. $content = "You have a new message from your contact formn=============================n";
  192.  
  193. foreach ($_POST as $key => $value) {
  194. // If the field exists in the $fields array, include it in the email
  195. if (isset($fields[$key])) {
  196. $content .= "$fields[$key]: $valuen";
  197. }
  198. }
  199.  
  200. // All the necessary headers for the email.
  201. $headers = array('Content-Type: text/plain; charset="UTF-8";',
  202. 'From: ' . $from,
  203. 'Reply-To: ' . $from,
  204. 'Return-Path: ' . $from,
  205. );
  206.  
  207. // Send email
  208. mail($to, $subject, $content, implode("n", $headers));
  209.  
  210. $responseArray = array('type' => 'success', 'message' => $okMessage);
  211. }
  212. catch (Exception $e)
  213. {
  214. $responseArray = array('type' => 'danger', 'message' => $errorMessage);
  215. }
  216.  
  217.  
  218. // if requested by AJAX request return JSON response
  219. if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  220. $encoded = json_encode($responseArray);
  221.  
  222. header('Content-Type: application/json');
  223.  
  224. echo $encoded;
  225. }
  226. // else just display the message
  227. else {
  228. echo $responseArray['message'];
  229. }
  230.  
  231. //recaptcha-response
  232. if($_SERVER["REQUEST_METHOD"] === "POST")
  233. {
  234.  
  235. $recaptcha_secret = "6LfK7ygUAAAAAIYzE6mbqdxbmuroi4gJWqdIpmBu";
  236. $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
  237. $response = json_decode($response, true);
  238.  
  239. if($response["success"] === true){
  240. echo "Form Submit Successfully.";
  241. }else{
  242. echo "You are a robot";
  243. }
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. require("sendgrid-php/sendgrid-php.php");
  252.  
  253. $from = new SendGridEmail("Namita", "demo@gmail.com");
  254. $subject = "Sending with SendGrid is Fun";
  255. $to = new SendGridEmail("Example User", "test@gmail.com");
  256. $content = new SendGridContent("text/plain", "and easy to do anywhere, even with PHP");
  257. $mail = new SendGridMail($from, $subject, $to, $content);
  258.  
  259. $apiKey = ('SG.-m74zeayRjGLKD2GPG__');
  260. $sg = new SendGrid($apiKey);
  261.  
  262. $response = $sg->client->mail()->send()->post($mail);
  263. echo $response->statusCode();
  264. print_r($response->headers());
  265. echo $response->body();
  266.  
  267.  
  268.  
  269. ?>
  270.  
  271.  
  272. **contact.js**
  273.  
  274. $(function () {
  275. $('#contact-form').validator();
  276.  
  277.  
  278. // when the form is submitted
  279. $('#contact_form').on('submit', function (e) {
  280.  
  281. // if the validator does not prevent form submit
  282. if (!e.isDefaultPrevented()) {
  283. var url = "contact.php";
  284.  
  285. // POST values in the background of the script URL
  286. $.ajax({
  287. type: "POST",
  288. url: url,
  289. data: $(this).serialize(),
  290. success: function (data)
  291. {
  292.  
  293. var messageAlert = 'alert-' + data.type;
  294. var messageText = data.message;
  295.  
  296. // let's compose Bootstrap alert box HTML
  297. var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';
  298.  
  299. // If we have messageAlert and messageText
  300. if (messageAlert && messageText) {
  301. // inject the alert to .messages div in our form
  302. $('#contact_form').find('.messages').html(alertBox);
  303. // empty the form
  304. $('#contact_form')[0].reset();
  305. }
  306. }
  307. });
  308. return false;
  309. }
  310. })
  311. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement