I am very familiar with HTML and CSS but have only started learning PHP recently.
I want people to be able to send me feedback through a form that collects their name, email address, a URL (if they have their own site), and a message. In the current state of the php script, I will receive the email with the requested information in the body of the email. Unfortunately, it comes into my spam folder because the from and reply-to headers are missing. This is expected because the from header is wrong (neither Email nor Name should be capitalized but when I un-capitalize them, the script no longer sends the email) and the reply-to header is missing entirely. I have tried every permutation to get Hotmail to show up the proper headers. Only this obviously wrong script works. I am absolutely perplexed.
After I get this blasted script to work, I also need to add some security measures. Can anyone please rework this script so that it works as it should and is secure?
Here is the semi-working code:
<?php
$to = "myemail@hotmail.com" ;
$subject = "Website Comments" ;
$name = $REQUEST['name'] ;
$email = $REQUEST['email'] ;
$URL = $REQUEST['URL'] ;
$message = $REQUEST['message'] ;
$ip = $REQUEST['ip'];
$httpref = $REQUEST['httpref'];
$httpagent = $_REQUEST['httpagent'];
$body = "Name: $name \n
Email: $email \n
URL: $URL \n
Message: $message \n
IP: $ip \n
Browser Information: $httpagent \n
Referral: $httpref \n" ;
$from = $REQUEST['Name'] ;
$from .= $REQUEST['Email'] ;
$send = mail( $to, $subject, $body, "From: $from" );
if($send)
{print "Your message was sent successfully. Please close this window.";}
else
{print "An error was encountered while sending your message. Please notify the webmaster."; }
?>