Answer the question
In order to leave comments, you need to log in
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
error 500
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question