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.

Recommended Answers

All 3 Replies

Try this:

mail($to, $subject, $body);

in place of what you have.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.