Guest User

Untitled

a guest
Mar 10th, 2018
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['submit'])) {
  3.  
  4. date_default_timezone_set('US/Central');
  5.  
  6. require 'PHPMailer-5.2.26/PHPMailerAutoload.php';
  7.  
  8. function sendemail(
  9. $SK_emailTo,
  10. $SK_emailSubject,
  11. $SK_emailBody
  12. ) {
  13.  
  14. $mail = new PHPMailer(true);
  15.  
  16. $mail->setFrom('myEmail@gmail.com', 'My Name');
  17.  
  18. $mail->addReplyTo($_POST['email'], $_POST['name']);
  19.  
  20. $mail->addAddress($SK_emailTo);
  21. $mail->Subject = $SK_emailSubject;
  22. $mail->Body = $SK_emailBody;
  23. $mail->isHTML(true);
  24.  
  25. $mail->isSMTP();
  26. $mail->Host = 'smtp.gmail.com';
  27. $mail->SMTPAuth = true;
  28. $mail->SMTPSecure = 'tls';
  29. $mail->Port = 587;
  30. $mail->Username = 'myEmail@gmail.com';
  31. $mail->Password = 'myPwd';
  32.  
  33. return $mail->send();
  34.  
  35. } //end function sendemail
  36.  
  37. $name = $_POST['name'];
  38. $email = $_POST['email'];
  39. $message = $_POST['message'];
  40.  
  41. try {
  42. sendemail(
  43. 'myEmail@address.com',
  44. 'First email subject',
  45. 'Form results to me...
  46. <br><br>'.$message
  47. );
  48. sendemail(
  49. $email,
  50. 'Second email subject',
  51. 'Confirmation email to person who submitted the form...
  52. <br><br>'.$message
  53. );
  54. echo 'Email sent!';
  55. } //end try
  56.  
  57. catch (phpmailerException $e) { //catches PHPMailer errors
  58. echo 'There is a problem; the message did NOT send. Please go back and check that you have filled in all the required fields and there are no typos in your email address.';
  59. echo $e->errorMessage();
  60. }
  61. catch (Exception $e) { //catches validation errors
  62. echo 'There is a problem; the message did NOT send. Please either go back and try again or contact us at email@address.com';
  63. echo $e->getMessage();
  64. }
  65.  
  66. function validateEmpty($string, $name = 'name') {
  67. $string = trim($string);
  68. if ($string == '') {
  69. throw new Exception(sprintf('%s is empty.', $name));
  70. }
  71. }
  72.  
  73. } //end if submit
  74. ?>
Add Comment
Please, Sign In to add comment