Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('phpmailer/PHPMailerAutoload.php');
  4.  
  5. $toemails = array();
  6.  
  7. $toemails[] = array(
  8. 'email' => 'recipient@domain.com', // Your Email Address
  9. 'name' => 'Recipient Name' // Your Name
  10. );
  11.  
  12.  
  13. $mail = new PHPMailer();
  14.  
  15. // If you intend you use SMTP, add your SMTP Code after this Line
  16. $mail->IsSMTP();
  17. $mail->Host = "mail.domain.com";
  18. $mail->SMTPDebug = 2;
  19. $mail->SMTPAuth = true;
  20. $mail->Port = 25;
  21. $mail->Username = "forms@domain.com";
  22. $mail->Password = "PaSsWoRd";
  23.  
  24.  
  25. if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  26. if( $_POST['template-contactform-email'] != '' ) {
  27.  
  28. $name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
  29. $email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
  30. $phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
  31. $company = isset( $_POST['template-contactform-company'] ) ? $_POST['template-contactform-company'] : '';
  32. $subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
  33. $message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';
  34.  
  35. $subject = isset($subject) ? $subject : 'New Message From Contact Form';
  36.  
  37. $botcheck = $_POST['template-contactform-botcheck'];
  38.  
  39. if( $botcheck == '' ) {
  40.  
  41. $mail->SetFrom( $email , $name );
  42. $mail->AddReplyTo( $email , $name );
  43. foreach( $toemails as $toemail ) {
  44. $mail->AddAddress( $toemail['email'] , $toemail['name'] );
  45. }
  46. $mail->Subject = $subject;
  47.  
  48. $name = isset($name) ? "Name: $name<br><br>" : '';
  49. $email = isset($email) ? "Email: $email<br><br>" : '';
  50. $phone = isset($phone) ? "Phone: $phone<br><br>" : '';
  51. $company = isset($company) ? "Firm or Company Name: $company<br><br>" : '';
  52. $message = isset($message) ? "Message: n$message<br><br>" : '';
  53.  
  54. $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';
  55.  
  56. $body = "$name $email $phone $company $message $referrer";
  57.  
  58.  
  59.  
  60. $mail->MsgHTML( $body );
  61. $sendEmail = $mail->Send();
  62.  
  63. if( $sendEmail == true ):
  64. //ORIGINAL ECHO OF SUCCESS MESSAGE
  65. //echo '{ "alert": "success", "message": "' . $message_success . '" }';
  66. //SWITCH TO REDIRECT
  67. header("Location: ../thank-you.php");
  68. else:
  69. 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 . '" }';
  70. endif;
  71. } else {
  72. echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }';
  73. }
  74. } else {
  75. echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }';
  76. }
  77. } else {
  78. echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }';
  79. }
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement