I have created a php contact form and for the most part it seems to work fine apart from when the sender is using a @yahoo email address. I have tested with hotmail and gmail addresses and all are being rceived OK.
I have used PHPMailer in order to try and avoid such problems but it still doesnt not seem to work.
Any help would be great and if you could provide example code that would be awesome!
as a side note - I am hosting the index.php file through godaddy (not sure if this could be causing an issue)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$msg = "";
if (isset($_POST['submit'])) {
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
function sendemail ($to, $from, $body) {
$mail = new PHPMailer(true);
$mail->setFrom($from);
$mail->addAddress($to);
$mail->Subject = 'Contact Form - Email';
$mail->Body = $body;
$mail->IsHTML(false);
return $mail->send();
}
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];
if (sendemail('example@gmail.com', $email, $subject, $body)) {
$msg = 'Email has been sent, thank you!';
} else
$msg = 'Email failed, please try again later';
}
?>
<title>Test Contact Form Using PHPMailer</title>
<body>
<div id="contactInnerWrapper">
<a href="#"><span id="close">×</span></a>
<h1 id="h1contactForm">Get in touch</h1>
<form method="post" action="index.php">
<label for="email">Email address:</label><br>
<input type="email" name="email" placeholder="Enter email" id="email">
<label for="subject">Subject:</label>
<input type="text" name="subject" id="subject"><br>
<label for="body">What would you like to ask us?</label><br>
<textarea type="text" name="body" rows="7" id="content"></textarea>
<button type="submit" name="submit" id="submit">Submit</button>
</form>
<br><br>
<?php echo $msg; ?>
</div>
</body>