Guest User

Untitled

a guest
Sep 13th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <?php
  2. // Import PHPMailer classes into the global namespace
  3. // These must be at the top of your script, not inside a function
  4. use PHPMailerPHPMailerPHPMailer;
  5. use PHPMailerPHPMailerException;
  6.  
  7. require 'vendor/autoload.php';
  8. if(isset($_POST['enviar'])) {
  9. if ($_POST['no-spam'] != ''){
  10. exit();
  11. }else {
  12. if (isset($_POST['name'], $_POST['email'], $_POST['comments'])){
  13. $mail = new PHPMailer(true);
  14. try {
  15. //Server settings
  16. $mail->SMTPDebug = 3;
  17. $mail->isSMTP();
  18. $mail->Host = '';
  19. $mail->SMTPAuth = true;
  20. $mail->Username = '';
  21. $mail->Password = '';
  22. $mail->SMTPSecure = 'ssl';
  23. $mail->Port = 465;
  24. $mail->SMTPOptions = array('ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ));
  25. //Recipients
  26. $mail->setFrom('', 'Formulario de contacto');
  27. $mail->addAddress('');
  28.  
  29. //Content
  30. $mail->isHTML(false);
  31. $mail->Subject = 'Cliente: '.$_POST['email'];
  32. $mail->Body = $_POST['comments'];
  33. $mail->AltBody = $_POST['comments'];;
  34.  
  35. $mail->send();
  36. header('Location: ../index_en.html');
  37.  
  38. } catch (Exception $e) {
  39. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  40. }
  41. }
  42.  
  43. }
  44.  
  45. <?php
  46. // según yo, el autoload debe ir primero para que funcione "use PHPMailer..." pero si te funciona...
  47. require 'vendor/autoload.php';
  48.  
  49. use PHPMailerPHPMailerException;
  50. use PHPMailerPHPMailerPHPMailer;
  51.  
  52. // esto lo puedes dar por subentendido
  53. // if(isset($_POST['enviar']))
  54.  
  55. function sendEmail()
  56. {
  57. if (!isset($_POST['no-spam']) || $_POST['no-spam'] != '') {
  58. return ['status' => 'error', 'msg' => 'parece que es spam'];
  59.  
  60. }
  61. if (!(isset($_POST['name'], $_POST['email'], $_POST['comments']))) {
  62. return ['status' => 'error', 'msg' => 'complete todos los campos'];
  63. }
  64.  
  65. $mail = new PHPMailer(true);
  66. try {
  67. //Server settings
  68. $mail->SMTPDebug = 3;
  69. $mail->isSMTP();
  70. $mail->Host = '';
  71. $mail->SMTPAuth = true;
  72. $mail->Username = '';
  73. $mail->Password = '';
  74. $mail->SMTPSecure = 'ssl';
  75. $mail->Port = 465;
  76. $mail->SMTPOptions = ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]];
  77. //Recipients
  78. $mail->setFrom('', 'Formulario de contacto');
  79. $mail->addAddress('');
  80.  
  81. //Content
  82. $mail->isHTML(false);
  83. $mail->Subject = 'Cliente: ' . $_POST['email'];
  84. $mail->Body = $_POST['comments'];
  85. $mail->AltBody = $_POST['comments'];
  86.  
  87. $mail->send();
  88. return ['status' => 'OK', 'msg' => 'mail enviado'];
  89.  
  90. } catch (Exception $e) {
  91. return ['status' => 'error', 'msg' => '$mail->ErrorInfo'];
  92. }
  93.  
  94. }
  95.  
  96. echo json_encode(sendEmail());
Add Comment
Please, Sign In to add comment