So i'm triyng to send emails using phpmailer (after committing a html form) to an email address provided by Hostinger.
Everything works fine, i also get the 'Mail was successfully sent!' message after hitting the submit button, but i don't see emails in the inbox.
No error alert displayed and SMTPDebug seems useful in this case. Also, this code works pretty fine in other websites (with different host password and username values).
php code
<?php
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
$subject = $_POST['subject'] ?? '';
$msg = $_POST['content'] ?? '';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer;
try {
$mail->Host='smtp.hostinger.es';
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->Username='emailLogin';
$mail->Password='passwordLogin';
$mail->setFrom($email, $name); // who send the email
$mail->addAddress('emailProvidedByHostinger'); // who recive the email
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->send();
header('Location: contacts.php?mailsent=1');
die(); // we don't want exactly anything after sending redirect header.
} catch (Exception $e){
echo '';
}
?>
html code
<form action="data.php" method="post">
<span class="contact">To contact us please compile this form and we will
answer you as soon as possible.
</span>
<ul class="form-content">
<?php
if (isset($_GET['mailsent']) && intval($_GET['mailsent']) == 1 ){
echo '<div class="messagesbox animate__animated animate__fadeInDown" style= "color: #1a5479;" >Mail was successfully sent!</div>';
}
?>
<li class="form-input">
<input class="input" id="name" type="text" name="name" placeholder="Full name" required>
</li>
<li class="form-input">
<input class="input" id="mail" type="text" name="email" placeholder="E-mail" required>
</li>
<li class="form-input">
<input class="input" id="subject" type="text" name="subject" placeholder="Subject" required>
</li>
<li class="form-input">
<textarea class="input" id="comment" type="text" name="content" placeholder="Insert text" cols="30" rows="10" style="resize: none;" required></textarea>
</li>
<li class="form-input paddingBottom0">
<input class="input" id="form-button" type="submit" value="submit" onclick="sendEmail()">
</li>
</ul>
</form>
I've talked to hostinger support and, from their side, everything is ok, so, i guess, i got to fix something in my code.
Anyone knows a solution?