Hi,
I'm trying to set a simple send an email script as I found it on the internet.
Here is the code:

<html>
<head>
<title>PHP Mail Array Loop</title>
</head>
<body>
<?php
$to = "mymail@anydomain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "anybody@somedomain.com";
$headers = "From: $from";

$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";

if (mail($to,$subject,$message,$headers))
{
echo "Mail Sent.";
}

?>
</body>
</html>

Email addresses are substituted by real addresses.
Now, this is not working. I see the "Mail Sent." message but receive no mail.

My php skills really suck and I would appreciate if you could help in this one.

Also change $to = "mymail@anydomain.com"; to your real email. In addition, another possible error which I am unsure if exists is that the if element may need to be as follows:

if (mail($to,$subject,$message,$headers))
{
mail($to,$subject,$message,$headers)
echo "Mail Sent.";
}

But I am unsure about if element and have never known if the mail function will work in the if element.

@cwarn23, mail function works fine in if condition. The mail function returns true on success and false on failure. It works just like, if(empty($var)) { @OP, check your spam folder. On many occasions, mails sent using php function lands up in spam folder!

This article has been dead for over six months. Start a new discussion instead.