C
C
carbanak012020-02-15 13:14:16
PHP
carbanak01, 2020-02-15 13:14:16

Why are emails not being sent to phpmailer?

Error 500 is displayed in the console when submitting the form

const request = new XMLHttpRequest();
var form = document.getElementById('form_underHead');
form.querySelector('.btn').addEventListener('click', (e)=>{
  e.preventDefault();
  let data = new FormData(document.getElementById('form_underHead'));
  request.open("POST",'/wp-content/themes/autopodbor/sendMail.php');
  request.addEventListener("readystatechange",()=>{
    if(request.readyState === 4 && request.status === 200){
      console.log(data)
    }
  });
  request.send(data);
})

require_once 'wp-content/themes/autopodbor/PHPMailer.php';
require_once 'wp-content/themes/autopodbor/SMTP.php';
require_once 'wp-content/themes/autopodbor/Exception.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try{
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host = 'ssl://smtp.mail.ru';                // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = '[email protected]';                     // SMTP username
    $mail->Password   = 'GRISHA2003';                               // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
    $mail->Port = 465;                                     // TCP port to connect to

    //Recipients
    $mail->setFrom('[email protected]');
    $mail->addAddress('[email protected]');     // Add a recipient
    //$mail->addAddress('[email protected]');             
    //$mail->addReplyTo('[email protected]', 'Information');
    //$mail->addCC('[email protected]');
    //$mail->addBCC('[email protected]');

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
}catch (Exception $e) {
  echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

<form id="form_underHead">
                    <div class="row-input">
                        <input type="text" id="name" name="name" class="inputxt inputxt-telephone" placeholder="Введите ваше имя" style="width:350px">
                    </div>
                    <div class="row-input">
                        <input type="tel" id="telephone" name="telephone" class="inputxt inputxt-telephone" placeholder="Введите ваш телефон" style="width:350px">
                    </div>
                    <div class="row-input">
                        <input type="submit" class="btn btn-wan-auto" value="Отправить" style="width:200px">
                    </div>
                </form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2020-02-15
@ThunderCat

error 500

1) You have disabled the output of errors and warnings, you can see all REAL execution errors in the server logs.
2) At the development stage, it is recommended to enable the display of all errors and warnings, so as not to climb the logos for every sneeze.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question