<?php
$msg="";
if(isset($_POST['submit']))
{
$from_add = "[email protected]";
$to_add = "[email protected]"; //<-- I replaced this with my real gmail account
$subject = "Test Subject";
$message = "Test Message";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent OK";
}
else
{
$msg = "Error sending email!";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test form to email</title>
</head>
<body>
<?php echo $msg ?>
<p>
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'>
<input type='submit' name='submit' value='Submit'>
</form>
</p>
</body>
</html>
I've got this code from http://www.html-form-guide.com, It's saying that it will check the configuration of my server if it is correctly configured to send emails.
I tried it, I uploaded it to my domain, and when I opened it, it shows the echo "Mail sent OK", but I do not receive the mail.
Please help me.
Check you server is setup to send mail.
What OS, mail server, are you using?
On Linux try running sendmail
from the command line.
echo 'this is a test'| mail -s test_email [email protected]
Other things to check is your mail settings in php.ini
are correct, there is no firewall blocking outgoing mail, and that the email is not getting caught by spam filters.