I have always used the following script in websites and can't get it to work this time.
Is it now deprecated or have i edited something wrong?
This is the header...
if (isset($_REQUEST['email']))
{
$to = "phil@phillipvale.com.au"; //insert correct email here
$subject = "California Tacos - Franchise Opportunities - Contact Form";
$message = "Name: " . $_REQUEST["firstname"] ["lastname"] . "
" . "Phone: " . $_REQUEST["phone"] . "
" . "Email: " . $_REQUEST["email"] . "
" ."State: " . $_REQUEST["state"] . "
" . "Comments: " . $_REQUEST["comments"];
$from = $_REQUEST['email'];
$headers = "From: $from";
mail($to,$subject,$message,$headers);
$strError = false;
}
else
{
$strError = true;
}
This is the form itself...
<form method="post" action="" id="myForm">
<?php
if ($strError != false)
{
?>
<label for="name">FIRST NAME</label>
<input name="firstname" type="text" required id="firstname" placeholder="Please enter your first name"/>
<label for="name">LAST NAME</label>
<input name="lastname" type="text" required id="lastname" placeholder="Please enter your last name"/>
<label for="email">EMAIL</label>
<input name="email" type="text" required id="email" placeholder="Please enter your email"/>
<label for="phone">PHONE</label>
<input name="phone" type="text" required id="phone" placeholder="Please enter your phone number"/>
<label for="state">WHERE DO YOU LIVE?</label>
<select name="state" id="state">
<option value="" disabled selected>Please select where you live</option>
<option value="New South Wales">New South Wales</option>
<option value="Queensland">Queensland</option>
<option value="South Australia">South Australia</option>
<option value="Tasmania">Tasmania</option>
<option value="Victoria">Victoria</option>
<option value="Western Australia">Western Australia</option>
</select>
<label for="comments">COMMENTS</label>
<textarea name="comments" required id="comments"></textarea>
<p><input name="submit" type="submit" value="SUBMIT"/></p>
<?php
}
else
{
?>
Thank you, We will be in touch shortly.
<?
}
?>
</form>
Thanks for any help,
Phil :)
To my eye the notation used $_REQUEST["firstname"] ["lastname"]
is wrong and likely to be causing issues. Make sure error_reporting is on when you try to debug scripts.
<?php
error_reporting( E_ALL );
if( isset( $_REQUEST['email'],$_REQUEST["firstname"],$_REQUEST["lastname"],$_REQUEST["phone"],$_REQUEST["email"] ) ){
$to = "phil@phillipvale.com.au";
$subject = "California Tacos - Franchise Opportunities - Contact Form";
$message = "Name: " . $_REQUEST["firstname"].' '.$_REQUEST["lastname"] . "
" . "Phone: " . $_REQUEST["phone"] . "
" . "Email: " . $_REQUEST["email"] . "
" ."State: " . $_REQUEST["state"] . "
" . "Comments: " . $_REQUEST["comments"];
$headers = "From: {$_REQUEST['email']}";
$result=mail( $to, $subject, $message, $headers );
}
echo $result ? 'Success' : 'Failed';
?>