I'm trying to use $headers = "From: webmaster@example.com\r\n";
in PHP to set the 'from' email address on a contact form to 'name@companyname.com'.
It is in reference to this answer PHP mail function 'from' address I'm quite new to php so apologies if the answer is obvious, but it's driving me around the bend.
The code for the form is below, but I can't seem to get it work? Does anyone know how/where I would integrate it in with the code below.
Kind regards,
<?php
if($_POST['submit']) {
if(!$_POST['name']) {
$error="<br>- Please enter your name";
}
if(!$_POST['email']) {
$error.="<br>- Please enter your email";
}
if(!$_POST['telephone']) {
$error.="<br>- Please enter your telephone number";
}
if(!$_POST['message']) {
$error.="<br>- Please enter your message";
}
if(!$_POST['checkbox']) {
$error.="<br>- Please confirm you agree to the Privacy Policy";
}
if ($error) {
$result='<div class="alert error">Whoops, there is an error. Please correct the following: '.$error.'</div>';
} else {
mail("name@company.com", "Contact Message", "Name: ".htmlspecialchars($_POST['name'])."
Email: ".htmlspecialchars($_POST['email'])."
Telephone: ".htmlspecialchars($_POST['telephone'])."
Company: ".htmlspecialchars($_POST['company'])."
Budget: ".htmlspecialchars($_POST['budget'])."
Message: ".htmlspecialchars($_POST['message']));
{
$_POST= array();
$result='<div class="alert thankyou" role="alert">THANK YOU! WE\'LL BE IN TOUCH SHORTLY...</div>';
}
}
}
?>