Support Forum

from mail in contact form 2017-03-13 19:10
fae

Hi,

I would like to know if I need a "from email" to send PHP (POST) form handler emails from my site. See below my script.


/* This email must be one set up on your domain for most hosts and is the email to send mail from */
$siteemailtosend="myviews@gmail.com";
/* This email is your email to receive the contact form details and can be the same as the one above if required */
$siteemailtoreceive="myviews@gmail.com";


// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
empty($_POST['phone']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No Values Provided!";
return false;
}

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$selection = strip_tags(htmlspecialchars($_POST['selection']));
$country = strip_tags(htmlspecialchars($_POST['country']));
$visa = strip_tags(htmlspecialchars($_POST['visa']));
$ipaddress = $_SERVER["REMOTE_ADDR">;
// Create the email and send the message
$to = $siteemailtoreceive;
$email_subject = "Website Contact From: $name";
$email_body = "You have received a new message from your website contact form.
\r
";
$email_body = $email_body."Here are the details:
\r
";
$email_body = $email_body."Name: $name
\r
";
$email_body = $email_body."Email: $email_address
\r
";
$email_body = $email_body."Phone: $phone
\r
";
$email_body = $email_body."Selection: $selection
\r
";
$email_body = $email_body."Selection: $country
\r
";
$email_body = $email_body."Selection: $visa
\r
";
$email_body = $email_body."Message:
$message

\r
";
$email_body = $email_body."Sender's IP Address: $ipaddress
\r
";
$headers = "From: $siteemailtosend
";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>


QUOTE
Re: from mail in contact form 2017-03-16 08:09
Panos

fae wrote: Hi,

I would like to know if I need a "from email" to send PHP (POST) form handler emails from my site. See below my script.

Your script looks fine, however "to" and "from" should be using different emails, otherwise it could cause issues. Wink


QUOTE
Latest updates
no login
2017-03-18 11:48
no access to account
2017-03-18 11:48
from mail in contact form
2017-03-16 08:09

What's going on?
Forum Statistics
Threads: 492, Posts: 1719
Members: 3647, Active Members: 2292
Welcome our newest member, Viral