Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Import PHPMailer classes into the global namespace
- // These must be at the top of your script, not inside a function
- use PHPMailerPHPMailerPHPMailer;
- use PHPMailerPHPMailerException;
- require 'vendor/autoload.php';
- if(isset($_POST['enviar'])) {
- if ($_POST['no-spam'] != ''){
- exit();
- }else {
- if (isset($_POST['name'], $_POST['email'], $_POST['comments'])){
- $mail = new PHPMailer(true);
- try {
- //Server settings
- $mail->SMTPDebug = 3;
- $mail->isSMTP();
- $mail->Host = '';
- $mail->SMTPAuth = true;
- $mail->Username = '';
- $mail->Password = '';
- $mail->SMTPSecure = 'ssl';
- $mail->Port = 465;
- $mail->SMTPOptions = array('ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ));
- //Recipients
- $mail->setFrom('', 'Formulario de contacto');
- $mail->addAddress('');
- //Content
- $mail->isHTML(false);
- $mail->Subject = 'Cliente: '.$_POST['email'];
- $mail->Body = $_POST['comments'];
- $mail->AltBody = $_POST['comments'];;
- $mail->send();
- header('Location: ../index_en.html');
- } catch (Exception $e) {
- echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
- }
- }
- }
- <?php
- // según yo, el autoload debe ir primero para que funcione "use PHPMailer..." pero si te funciona...
- require 'vendor/autoload.php';
- use PHPMailerPHPMailerException;
- use PHPMailerPHPMailerPHPMailer;
- // esto lo puedes dar por subentendido
- // if(isset($_POST['enviar']))
- function sendEmail()
- {
- if (!isset($_POST['no-spam']) || $_POST['no-spam'] != '') {
- return ['status' => 'error', 'msg' => 'parece que es spam'];
- }
- if (!(isset($_POST['name'], $_POST['email'], $_POST['comments']))) {
- return ['status' => 'error', 'msg' => 'complete todos los campos'];
- }
- $mail = new PHPMailer(true);
- try {
- //Server settings
- $mail->SMTPDebug = 3;
- $mail->isSMTP();
- $mail->Host = '';
- $mail->SMTPAuth = true;
- $mail->Username = '';
- $mail->Password = '';
- $mail->SMTPSecure = 'ssl';
- $mail->Port = 465;
- $mail->SMTPOptions = ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]];
- //Recipients
- $mail->setFrom('', 'Formulario de contacto');
- $mail->addAddress('');
- //Content
- $mail->isHTML(false);
- $mail->Subject = 'Cliente: ' . $_POST['email'];
- $mail->Body = $_POST['comments'];
- $mail->AltBody = $_POST['comments'];
- $mail->send();
- return ['status' => 'OK', 'msg' => 'mail enviado'];
- } catch (Exception $e) {
- return ['status' => 'error', 'msg' => '$mail->ErrorInfo'];
- }
- }
- echo json_encode(sendEmail());
Add Comment
Please, Sign In to add comment