Wednesday, November 13, 2019

html - Send mail by php mail() function

I have problem with sending mail message by php mail() function. I'm not sure if it's problem with code coz I have read that some hosting servers are not allowing to sends mail but I'm trying to send this mail also when website is on localhost and it still doesn't work - after click "Send" I see the information: "Your mail is sent", but when I'm checking on my postbox there is no mails (also in spam).



For me code looks good but maybe I'm missing something. The second option which I'm considering is that also my localhost is not allowing to send mails.

























srand((double)microtime()*1000000);
$marker = md5(uniqid(rand()));


$receiver = "address@gmail.com";
$title = "Mail";
$sender = $_POST['name'];
$sender .= $_POST['surname'];
$sender_mail = $_POST['mail'];

$message = $_POST['message'];

$headers = "From: $sender <$sender_mail>\n";
$headers .= "MIME-Version: 1.0\n";

$headers .= "Content-Type: multipart/mixed;\n";
$headers .= "\tboundary=\"___$marker==\"";

$content ="--___$marker==\n";
$content .="Content-Type: text/plain; charset=\"iso-8859-2\"\n";
$content .="Content-Transfer-Encoding: 8bit\n";
$content .="\n$message\n";

if (mail($receiver,$title,$content,$headers))
{

print "Your message is sent.";
} else {
print "Your message is not sent.

Please go back and send again.";
}
?>


Pictures with my php conf:




PHP config
PHP config
PHP config

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...