Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ( ! ) 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
- Call Stack
- # Time Memory Function Location
- 1 0.0005 262960 {main}( ) ...contact.php:0
- 2 0.0006 267424 mail ( ) ...contact.php:50
- 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] => )
- echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
- echo "sendgrid.env" >> .gitignore
- source ./sendgrid.env
- **index.php**
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
- <title>Contact Form</title>
- <!-- Bootstrap -->
- <link href="css/bootstrap.min.css" rel="stylesheet">
- <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
- <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
- <!--[if lt IE 9]>
- <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
- <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
- <![endif]-->
- </head>
- <body>
- <div class="container">
- <div class="row">
- <div class="col-md-12">
- <div class="row">
- <h2 class="contact-title">Contact US</h2>
- </div>
- </div>
- <span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span>
- <div class="row">
- <div class="col-md-6">
- <p>University</p>
- </div>
- </div>
- <span class="glyphicon glyphicon-earphone" aria-hidden="true"></span>
- <div class="row">
- <div class="col-md-6">
- <p>+81 (0)3 54</p>
- </div>
- </div>
- <div class="row" style="border: solid 1px #000000;"></div>
- <div class="col-md-12">
- <div class="row">
- <h2 class="contact-title">Get In Touch</h2>
- </div>
- </div>
- <form id="contact-form" method="post" action="contact.php" role="form">
- <div class="messages"></div>
- <div class="controls">
- <div class="row">
- <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
- <div class="form-group">
- <label for="form_name">Name *</label>
- <input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your name" required="required" data-error="Name is required.">
- <div class="help-block with-errors"></div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-6">
- <div class="form-group">
- <label for="form_email">Email *</label>
- <input id="form_email" type="email" name="email" class="form-control" placeholder="example@domain.com " required="required" data-error="Valid email is required.">
- <div class="help-block with-errors"></div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-6">
- <div class="form-group">
- <label for="form_phone">Phone</label>
- <input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
- <div class="help-block with-errors"></div>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-6">
- <div class="form-group">
- <label for="form_subject">Subject *</label>
- <textarea id="form_subject" name="subject" class="form-control" placeholder="Subject " rows="4" required="required" data-error="Enter Subject"></textarea>
- <div class="help-block with-errors"></div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-6">
- <div class="form-group">
- <label for="form_message">Message *</label>
- <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>
- <div class="help-block with-errors"></div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-6">
- <div class="form-group">
- <label class="control-label">Captcha:</label>
- <div class="g-recaptcha" data-sitekey="6LfK7ygUAAAAAAKW"></div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <input type="submit" class="btn btn-success btn-send" value="Send message">
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <p class="text-muted"><strong>*</strong> These fields are required. </p>
- </div>
- </div>
- </div>
- </form>
- <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
- <!-- Include all compiled plugins (below), or include individual files as needed -->
- <script src="js/bootstrap.min.js"></script>
- <script src="contact.js"></script>
- <script src="https://www.google.com/recaptcha/api.js"></script>
- </body>
- </html>
- **contact.php**
- <?php
- // an email address that will be in the From field of the email.
- $from = 'Demo contact form <demo@gmail.com >';
- // an email address that will receive the email with the output of the form
- $to = 'Demo contact form <test@gmail.com>';
- // subject of the email
- $subject = 'New Message Recieved';
- // form field names and their translations.
- // array variable name => Text to appear in the email
- $fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message');
- // message that will be displayed when everything is OK :)
- $okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
- // If something goes wrong, we will display this message.
- $errorMessage = 'There was an error while submitting the form. Please try again later';
- /*
- * LET'S DO THE SENDING
- */
- // if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
- error_reporting(E_ALL & ~E_NOTICE);
- try
- {
- if(count($_POST) == 0) throw new Exception('Form is empty');
- $content = "You have a new message from your contact formn=============================n";
- foreach ($_POST as $key => $value) {
- // If the field exists in the $fields array, include it in the email
- if (isset($fields[$key])) {
- $content .= "$fields[$key]: $valuen";
- }
- }
- // All the necessary headers for the email.
- $headers = array('Content-Type: text/plain; charset="UTF-8";',
- 'From: ' . $from,
- 'Reply-To: ' . $from,
- 'Return-Path: ' . $from,
- );
- // Send email
- mail($to, $subject, $content, implode("n", $headers));
- $responseArray = array('type' => 'success', 'message' => $okMessage);
- }
- catch (Exception $e)
- {
- $responseArray = array('type' => 'danger', 'message' => $errorMessage);
- }
- // if requested by AJAX request return JSON response
- if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
- $encoded = json_encode($responseArray);
- header('Content-Type: application/json');
- echo $encoded;
- }
- // else just display the message
- else {
- echo $responseArray['message'];
- }
- //recaptcha-response
- if($_SERVER["REQUEST_METHOD"] === "POST")
- {
- $recaptcha_secret = "6LfK7ygUAAAAAIYzE6mbqdxbmuroi4gJWqdIpmBu";
- $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
- $response = json_decode($response, true);
- if($response["success"] === true){
- echo "Form Submit Successfully.";
- }else{
- echo "You are a robot";
- }
- }
- require("sendgrid-php/sendgrid-php.php");
- $from = new SendGridEmail("Namita", "demo@gmail.com");
- $subject = "Sending with SendGrid is Fun";
- $to = new SendGridEmail("Example User", "test@gmail.com");
- $content = new SendGridContent("text/plain", "and easy to do anywhere, even with PHP");
- $mail = new SendGridMail($from, $subject, $to, $content);
- $apiKey = ('SG.-m74zeayRjGLKD2GPG__');
- $sg = new SendGrid($apiKey);
- $response = $sg->client->mail()->send()->post($mail);
- echo $response->statusCode();
- print_r($response->headers());
- echo $response->body();
- ?>
- **contact.js**
- $(function () {
- $('#contact-form').validator();
- // when the form is submitted
- $('#contact_form').on('submit', function (e) {
- // if the validator does not prevent form submit
- if (!e.isDefaultPrevented()) {
- var url = "contact.php";
- // POST values in the background of the script URL
- $.ajax({
- type: "POST",
- url: url,
- data: $(this).serialize(),
- success: function (data)
- {
- var messageAlert = 'alert-' + data.type;
- var messageText = data.message;
- // let's compose Bootstrap alert box HTML
- var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + messageText + '</div>';
- // If we have messageAlert and messageText
- if (messageAlert && messageText) {
- // inject the alert to .messages div in our form
- $('#contact_form').find('.messages').html(alertBox);
- // empty the form
- $('#contact_form')[0].reset();
- }
- }
- });
- return false;
- }
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement