SHARE
TWEET

Untitled

a guest May 7th, 2016 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if( $_SERVER["REQUEST_METHOD"] == "POST" ) {
  2.  
  3.     require 'phpmailer/PHPMailerAutoload.php';
  4.  
  5.     $mail = new PHPMailer(true);
  6.     $mail->isSMTP();
  7.     $mail->SMTPSecure = 'tls';
  8.     $mail->Port = 587;
  9.     $mail->SMTPDebug = 0;
  10.     $mail->SMTPAuth = true;
  11.     $mail->isHTML(false);
  12.  
  13.     $mail->Host = gethostbyname('secret'); // Specify main and backup SMTP servers ("smtp.gmail.com" is original value)
  14.     $mail->Username = 'secret'; // Email account address
  15.     $mail->Password = 'secret'; // Email account password
  16.     $mail->addAddress('secret', 'secret'); // Send emails to this address
  17.  
  18.     $input3Exist = isset($_POST['form-input-3']);
  19.  
  20.     $formInput1 = $_REQUEST['form-input-1'];
  21.     $formInput2 = $_REQUEST['form-input-2'];
  22.     $formInput4 = $_REQUEST['form-input-4'];
  23.     if( $input3Exist ) { $formInput3 = $_REQUEST['form-input-3']; }
  24.  
  25.     if( trim($formInput1) !== '' && trim($formInput2) !== '' && trim($formInput4) !== '' ) {
  26.         try {
  27.             $mail->setFrom($formInput2, $formInput1);
  28.             $mail->addReplyTo($formInput2, $formInput1);
  29.             $mail->Body = $formInput4;
  30.             if( $input3Exist && trim($formInput3) !== '' ) { $mail->Subject = $formInput3; } else { $mail->Subject = 'New Email From: '.$formInput1; } // if input 3 exists
  31.             if( isset($_FILES['form-4-file']) && $_FILES['form-4-file']['error'] == UPLOAD_ERR_OK ) { $mail->addAttachment( $_FILES['form-4-file']['tmp_name'], $_FILES['form-4-file']['name'] ); } // attachments
  32.  
  33.             !$mail->send(); // Send email
  34.             echo 'Message Sent';
  35.         } catch ( phpmailerException $e ) {
  36.             echo $e->errorMessage();
  37.         } catch ( Exception $e ) {
  38.             echo $e->getMessage();
  39.         }
  40.     } else {
  41.         echo 'One or more required fields are empty';
  42.     }
  43.  
  44. } else {
  45.     http_response_code(403);
  46. }
  47.    
  48. form.submit(function(event) {
  49.     var formSerial = form.serialize();
  50.     // Set original message, Disable response hiding, Show form message container
  51.     submitResponseContainer.html(origFormMessage);
  52.     closeFormAjaxSubmitResponse = false;
  53.     form.find(".form-ajax-submit-response").show("puff", 300, "easeInOutQuad");
  54.     // Send form data to 'send-email.php'
  55.     $.ajax({
  56.         type: "POST",
  57.         url: form.attr("action"),
  58.         data: formSerial,
  59.         complete: function() {
  60.             closeFormAjaxSubmitResponse = true;
  61.         }
  62.     }).done(function(response) {
  63.         submitResponseContainer.html(response);
  64.     }).fail(function() {
  65.         submitResponseContainer.html("<p>An error occured. The message could not be sent.</p>")
  66.     });
  67.     // prevent default form submission
  68.     event.preventDefault();
  69. })
  70.    
  71. <form action="php/send-email.php" method="post" enctype="multipart/form-data">
  72.                                 <div class="form-ajax-submit-response">
  73.                                     <div class="form-ajax-submit-response-content">
  74.                                         <i class="fa fa-refresh fa-spin"></i>
  75.                                         <div class="form-ajax-submit-response-message">Sending Message...</div>
  76.                                     </div>
  77.                                 </div>
  78.                                 <div class="form-4-top">
  79.                                     <div class="form-4-section-1 input-focus-label-highlight">
  80.                                         <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Your Name</span>
  81.                                         <input class="input-text-field-style" type="text" name="form-input-1" placeholder="John Doe"/>
  82.                                     </div>
  83.                                     <div class="form-4-section-2 input-focus-label-highlight">
  84.                                         <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Email Address</span>
  85.                                         <input class="input-text-field-style" type="text" name="form-input-2" placeholder="JohnDoe@gmail.com"/>
  86.                                     </div>
  87.                                     <div class="form-4-section-3 input-focus-label-highlight">
  88.                                         <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Subject(optional)</span>
  89.                                         <input class="input-text-field-style" type="text" name="form-input-3" placeholder="Feature Request"/>
  90.                                     </div>
  91.                                 </div>
  92.                                 <div class="form-4-middle">
  93.                                     <span class="form-4-input-label">Include Attachment</span>
  94.                                     <label class="forms-input-file-style">
  95.                                         <span class="forms-input-file-span"><i class="fa fa-upload"></i><span class="forms-input-file-val" data-pb-editable-text>Choose a file...</span></span>
  96.                                         <input type="file" name="form-4-file" data-multiple-files-text="Files Selected" data-no-files-text="No Files Selected"/>
  97.                                     </label>
  98.                                 </div>
  99.                                 <div class="form-4-bottom input-focus-label-highlight">
  100.                                     <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Message</span>
  101.                                     <textarea class="input-text-field-style" name="form-input-4" placeholder="(5000 Characters Max)" data-pb-height-option="Text Area Height"></textarea>
  102.                                     <a data-submit-form role="button"><i class="fa fa-send"></i><span data-pb-editable-text="">Send Email</span></a>
  103.                                 </div>
  104.                             </form>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top