Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // you need to replace your SMTP login details here
  3. // this script is working for sending mail but not making a proper js call back yet
  4. use PHPMailer\PHPMailer\PHPMailer;
  5. use PHPMailer\PHPMailer\Exception;
  6. require 'phpmailer/Exception.php';
  7. require 'phpmailer/PHPMailer.php';
  8. require 'phpmailer/SMTP.php';
  9. //$mail->SMTPDebug = 2;
  10. // this should catch a lot of spam bots
  11. $honeypot = trim($_POST["email"]);
  12. if(!empty($honeypot)) {
  13. echo "BAD ROBOT!";
  14. exit;
  15. }
  16. $msg = '';
  17. //Don't run this unless we're handling a form submission
  18. if (array_key_exists('email', $_POST)) {
  19. date_default_timezone_set('Etc/UTC');
  20. $mail = new PHPMailer;
  21. //Tell PHPMailer to use SMTP - requires a local mail server
  22. //Faster and safer than using mail()
  23. $mail->isSMTP(); // Set mailer to use SMTP
  24. $mail->Host = 'smtp.server.net'; // Specify main and backup SMTP servers
  25. $mail->SMTPAuth = true; // Enable SMTP authentication
  26. $mail->Username = 'mailer@server.net'; // SMTP username
  27. $mail->Password = 'mailerPASSWord'; // SMTP password
  28. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  29. $mail->Port = 25; // TCP port to connect to
  30. //Use a fixed address in your own domain as the from address
  31. //**DO NOT** use the submitter's address here as it will be forgery
  32. //and will cause your messages to fail SPF checks
  33. $mail->setFrom('sender@server.net', 'Your Name');
  34. //Send the message to yourself, or whoever should receive contact for submissions
  35. $mail->addAddress('testsendmail@greenant.net', 'Your Name');
  36. //Put the submitter's address in a reply-to header
  37. //This will fail if the address provided is invalid,
  38. //in which case we should ignore the whole request
  39. if ($mail->addReplyTo($_POST['email_real'], $_POST['name'])) {
  40. $mail->Subject = 'PHPMailer contact form';
  41. //Keep it simple - don't use HTML
  42. $mail->isHTML(false);
  43. //Build a simple message body
  44. $mail->Body = <<<EOT
  45. Email: {$_POST['email_real']}
  46. Name: {$_POST['name']}
  47. Message: {$_POST['message']}
  48. EOT;
  49. //Send the message, check for errors
  50. if (!$mail->send()) {
  51. //The reason for failing to send will be in $mail->ErrorInfo
  52. //but you shouldn't display errors to users - process the error, log it on your server.
  53. $msg = 'Sorry, something went wrong. Please try again later.';
  54. } else {
  55. $msg = 'sent';
  56. }
  57. } else {
  58. $msg = 'Invalid email address, message ignored.';
  59. }
  60. echo $msg;
  61. return $msg;
  62. //exit;
  63. }
  64. ?>