SHARE
TWEET

MailerFailerDay2

a guest Jun 8th, 2017 548 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. require_once('phpmailer/PHPMailerAutoload.php');
  4.  
  5. $toemails = array();
  6.  
  7. $toemails[] = array(
  8.                 'email' => '----@yahoo.com', // Your Email Address
  9.                 'name' => '----' // Your Name
  10.             );
  11.  
  12. // Form Processing Messages
  13. $message_success = 'We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.';
  14.  
  15. // Add this only if you use reCaptcha with your Contact Forms
  16. $recaptcha_secret = 'your-recaptcha-secret-key'; // Your reCaptcha Secret
  17.  
  18. $mail = new PHPMailer();
  19.  
  20. // If you intend you use SMTP, add your SMTP Code after this Line
  21. $mail->IsSMTP();
  22. $mail->Host = "smtp.mail.yahoo.com";
  23. // I also tried Debug = 2, the form never submitted - spun forever
  24. $mail->SMTPDebug = 0;
  25. $mail->SMTPAuth = true;
  26. $mail->Port = 587;
  27. $mail->SMTPSecure = 'tls';
  28. $mail->Username = "----@yahoo.com";
  29. $mail->Password = "----";
  30.  
  31.  
  32. if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  33.     if( $_POST['template-contactform-email'] != '' ) {
  34.  
  35.         $name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
  36.         $email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
  37.         $phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
  38.         $service = isset( $_POST['template-contactform-service'] ) ? $_POST['template-contactform-service'] : '';
  39.         $subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
  40.         $message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';
  41.  
  42.         $subject = isset($subject) ? $subject : 'New Message From Contact Form';
  43.  
  44.         $botcheck = $_POST['template-contactform-botcheck'];
  45.  
  46.         if( $botcheck == '' ) {
  47.  
  48.             $mail->SetFrom( "----@yahoo.com", $name );
  49.             $mail->AddReplyTo( $email , $name );
  50.             foreach( $toemails as $toemail ) {
  51.                 $mail->AddAddress( $toemail['email'] , $toemail['name'] );
  52.             }
  53.             $mail->Subject = $subject;
  54.  
  55.             $name = isset($name) ? "Name: $name<br><br>" : '';
  56.             $email = isset($email) ? "Email: $email<br><br>" : '';
  57.             $phone = isset($phone) ? "Phone: $phone<br><br>" : '';
  58.             $service = isset($service) ? "Service: $service<br><br>" : '';
  59.             $message = isset($message) ? "Message: $message<br><br>" : '';
  60.  
  61.             $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';
  62.  
  63.             $body = "$name $email $phone $service $message $referrer";
  64.  
  65.             // Runs only when File Field is present in the Contact Form
  66.             if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
  67.                 $mail->IsHTML(true);
  68.                 $mail->AddAttachment( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
  69.             }
  70.  
  71.             // Runs only when reCaptcha is present in the Contact Form
  72.             if( isset( $_POST['g-recaptcha-response'] ) ) {
  73.                 $recaptcha_response = $_POST['g-recaptcha-response'];
  74.                 $response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response );
  75.  
  76.                 $g_response = json_decode( $response );
  77.  
  78.                 if ( $g_response->success !== true ) {
  79.                     echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }';
  80.                     die;
  81.                 }
  82.             }
  83.  
  84.             $mail->MsgHTML( $body );
  85.             $sendEmail = $mail->Send();
  86.  
  87.             if( $sendEmail == true ):
  88.                 echo '{ "alert": "success", "message": "' . $message_success . '" }';
  89.             else:
  90.                 echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }';
  91.             endif;
  92.         } else {
  93.             echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }';
  94.         }
  95.     } else {
  96.         echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }';
  97.     }
  98. } else {
  99.     echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }';
  100. }
  101.  
  102. ?>
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