Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( $_SERVER["REQUEST_METHOD"] == "POST" ) {
- require 'phpmailer/PHPMailerAutoload.php';
- $mail = new PHPMailer(true);
- $mail->isSMTP();
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
- $mail->SMTPDebug = 0;
- $mail->SMTPAuth = true;
- $mail->isHTML(false);
- $mail->Host = gethostbyname('secret'); // Specify main and backup SMTP servers ("smtp.gmail.com" is original value)
- $mail->Username = 'secret'; // Email account address
- $mail->Password = 'secret'; // Email account password
- $mail->addAddress('secret', 'secret'); // Send emails to this address
- $input3Exist = isset($_POST['form-input-3']);
- $formInput1 = $_REQUEST['form-input-1'];
- $formInput2 = $_REQUEST['form-input-2'];
- $formInput4 = $_REQUEST['form-input-4'];
- if( $input3Exist ) { $formInput3 = $_REQUEST['form-input-3']; }
- if( trim($formInput1) !== '' && trim($formInput2) !== '' && trim($formInput4) !== '' ) {
- try {
- $mail->setFrom($formInput2, $formInput1);
- $mail->addReplyTo($formInput2, $formInput1);
- $mail->Body = $formInput4;
- if( $input3Exist && trim($formInput3) !== '' ) { $mail->Subject = $formInput3; } else { $mail->Subject = 'New Email From: '.$formInput1; } // if input 3 exists
- 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
- !$mail->send(); // Send email
- echo 'Message Sent';
- } catch ( phpmailerException $e ) {
- echo $e->errorMessage();
- } catch ( Exception $e ) {
- echo $e->getMessage();
- }
- } else {
- echo 'One or more required fields are empty';
- }
- } else {
- http_response_code(403);
- }
- form.submit(function(event) {
- var formSerial = form.serialize();
- // Set original message, Disable response hiding, Show form message container
- submitResponseContainer.html(origFormMessage);
- closeFormAjaxSubmitResponse = false;
- form.find(".form-ajax-submit-response").show("puff", 300, "easeInOutQuad");
- // Send form data to 'send-email.php'
- $.ajax({
- type: "POST",
- url: form.attr("action"),
- data: formSerial,
- complete: function() {
- closeFormAjaxSubmitResponse = true;
- }
- }).done(function(response) {
- submitResponseContainer.html(response);
- }).fail(function() {
- submitResponseContainer.html("<p>An error occured. The message could not be sent.</p>")
- });
- // prevent default form submission
- event.preventDefault();
- })
- <form action="php/send-email.php" method="post" enctype="multipart/form-data">
- <div class="form-ajax-submit-response">
- <div class="form-ajax-submit-response-content">
- <i class="fa fa-refresh fa-spin"></i>
- <div class="form-ajax-submit-response-message">Sending Message...</div>
- </div>
- </div>
- <div class="form-4-top">
- <div class="form-4-section-1 input-focus-label-highlight">
- <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Your Name</span>
- <input class="input-text-field-style" type="text" name="form-input-1" placeholder="John Doe"/>
- </div>
- <div class="form-4-section-2 input-focus-label-highlight">
- <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Email Address</span>
- <input class="input-text-field-style" type="text" name="form-input-2" placeholder="JohnDoe@gmail.com"/>
- </div>
- <div class="form-4-section-3 input-focus-label-highlight">
- <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Subject(optional)</span>
- <input class="input-text-field-style" type="text" name="form-input-3" placeholder="Feature Request"/>
- </div>
- </div>
- <div class="form-4-middle">
- <span class="form-4-input-label">Include Attachment</span>
- <label class="forms-input-file-style">
- <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>
- <input type="file" name="form-4-file" data-multiple-files-text="Files Selected" data-no-files-text="No Files Selected"/>
- </label>
- </div>
- <div class="form-4-bottom input-focus-label-highlight">
- <span class="form-4-input-label input-focus-label" data-pb-editable-text="">Message</span>
- <textarea class="input-text-field-style" name="form-input-4" placeholder="(5000 Characters Max)" data-pb-height-option="Text Area Height"></textarea>
- <a data-submit-form role="button"><i class="fa fa-send"></i><span data-pb-editable-text="">Send Email</span></a>
- </div>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement