Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Name: Demo Form
- */
- ini_set('allow_url_fopen', true);
- session_cache_limiter('nocache');
- header('Expires: ' . gmdate('r', 0));
- header('Content-type: application/json');
- if(isset($_POST['recaptcha']) && !empty($_POST['recaptcha']))
- {
- //your site secret key
- $secret = '6Lfs1R0UAAAAABBa_bGcxwtnwmhASeY3ia5GltNJ';
- if( function_exists('curl_version') ) {
- // reCAPTCHA - Using CURL
- $fields = array(
- 'secret' => $secret,
- 'response' => $_POST['recaptcha'],
- 'remoteip' => $_SERVER['REMOTE_ADDR']
- );
- $verifyResponse = curl_init("https://www.google.com/recaptcha/api/siteverify");
- curl_setopt($verifyResponse, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($verifyResponse, CURLOPT_TIMEOUT, 15);
- curl_setopt($verifyResponse, CURLOPT_POSTFIELDS, http_build_query($fields));
- $responseData = json_decode(curl_exec($verifyResponse));
- curl_close($verifyResponse);
- } else {
- $arrResult = array ('response'=>'error','errorMessage'=>'You need CURL or file_get_contents() activated in your server. Please contact your host to activate.');
- echo json_encode($arrResult);
- die();
- }
- if($responseData->success) {
- require_once('php-mailer/PHPMailerAutoload.php');
- // Step 1 - Enter your email address below.
- $email = 'adortok@ndacorp.com';
- // If the e-mail is not working, change the debug option to 2 | $debug = 2;
- $debug = 0;
- $fields = array(
- 0 => array(
- 'text' => 'Name',
- 'val' => $_POST['name']
- ),
- 1 => array(
- 'text' => 'Email',
- 'val' => $_POST['email']
- ),
- 2 => array(
- 'text' => 'Company',
- 'val' => $_POST['company']
- ),
- 3 => array(
- 'text' => 'Phone',
- 'val' => $_POST['phone']
- ),
- 4 => array(
- 'text' => 'Region',
- 'val' => $_POST['region']
- ),
- 5 => array(
- 'text' => 'Checkboxes',
- 'val' => implode($_POST['checkboxes'], ", ")
- ),
- 6 => array(
- 'text' => 'Additional Info',
- 'val' => $_POST['comment']
- )
- );
- $message = '';
- foreach($fields as $field) {
- $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
- }
- $mail = new PHPMailer(true);
- try {
- $mail->SMTPDebug = $debug; // Debug Mode
- // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
- $mail->IsSMTP(); // Set mailer to use SMTP
- $mail->Host = '10.10.1.32'; // Specify main and backup server
- //$mail->SMTPAuth = true; // Enable SMTP authentication
- //$mail->Username = 'user@example.com'; // SMTP username
- //$mail->Password = 'secret'; // SMTP password
- //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
- //$mail->Port = 587; // TCP port to connect to
- $mail->AddAddress($email); // Add another recipient
- //$mail->AddAddress('person2@domain.com', 'Person 2'); // Add a secondary recipient
- //$mail->AddCC('person3@domain.com', 'Person 3'); // Add a "Cc" address.
- //$mail->AddBCC('person4@domain.com', 'Person 4'); // Add a "Bcc" address.
- $mail->SetFrom('nda@ndacorp.com', $_POST['name']);
- $mail->AddReplyTo($_POST['email'], $_POST['name']);
- $mail->IsHTML(true); // Set email format to HTML
- $mail->CharSet = 'UTF-8';
- $mail->Subject = 'Demo Request Submitted';
- $mail->Body = $message;
- $mail->Send();
- $arrResult = array ('response'=>'success');
- } catch (phpmailerException $e) {
- $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
- } catch (Exception $e) {
- $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
- }
- if ($debug == 0) {
- echo json_encode($arrResult);
- }
- } else {
- $arrResult = array ('response'=>'error','errorMessage'=>'Robot verification failed, please try again');
- echo json_encode($arrResult);
- }
- } else {
- $arrResult = array ('response'=>'error','errorMessage'=>'Please click on the reCAPTCHA box.');
- echo json_encode($arrResult);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement