I have a problem with my form. The functionality of sending information to an email is good thanks to PHPMailer , when you submit, the information is sent to a php file called contacto.php, this is where I check that it is not spam and I think the mail to finally send it to my account. When all the logic of the program ends, by means of a header I return to the initial page, causing it to load again. That last is what I want to avoid. I would like the submit to be done, and once sent, the user remains positioned on the form.
I leave the code of the php file where the logic of sending information by mail is. The action of the form points to here:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
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;
}
}
}
}
Quito personal code data by privacy.