I'm trying to test out a simple email form on my website to see if I can get it to work. The email sends out just fine, but when I use my yahoo email address as the recipient for incoming emails to test it, no email ever arrives. I'm hard pressed to figure out why
This is the PHP code I'm using.
<?php
// Message Vars
$msg = '';
$msgClass = '';
// Check For Submit
if(filter_has_var(INPUT_POST, 'submit')){
// Get Form Data
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$message = htmlspecialchars($_POST['message']);
// Check Required Fields
if(!empty($email) && !empty($name) && !empty($message)){
// Passed
// Check Email
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
// Failed
$msg = 'Please use a valid email';
$msgClass = 'alert-danger';
} else{
// Passed
// Recipient Email
$toEmail = 'dylancougar@yahoo.com';
$subject = 'Contact Request From '.$name;
$body = '<h2>Contact Request</h2>
<h4>Name</h4><p>'.$name.'</p>
<h4>Email</h4><p>'.$email.'</p>
<h4>Message</h4><p>'.$message.'</p>
';
// Email Headers
$headers = "MIME-Version: 1.0" ."\r\n";
$headers .="Content-Type:text/html;charset=UTF-8" . "\r\n";
// Additional Headers
$headers .= "From: " .$name. "<".$email.">". "\r\n";
if(mail($toEmail, $subject, $body, $headers)){
// Email Sent
$msg = 'Your email has been sent';
$msgClass = 'alert-success';
} else {
// Failed
$msg = 'Your email was not sent';
$msgClass = 'alert-danger';
}
}
} else {
// Failed
$msg = 'Please fill in all fields';
$msgClass = 'alert-danger';
}
}
?>
Solved! Go to Solution.
Could be a few things. I did a quick search to see what others have done for troubleshooting PHP mail. This useful list came up in a Stack Overflow thread:
Let us know how you make out. 🙂
Could be a few things. I did a quick search to see what others have done for troubleshooting PHP mail. This useful list came up in a Stack Overflow thread:
Let us know how you make out. 🙂
So I'm guessing that the recipient for incoming emails has to be on a Go daddy server. I used my Godaddy email address and this time it actually worked.