I have a “Contact Us” form on a page running locally. I use AJAX to dynamically create and send the query to the PHP script, which “should” extract the variables and send it in the mail. However for some reason when I extract the “$_POST”, all the variables return empty. I am self taught at PHP, so my syntax might not be correct, or it’s possible that I am missing something. Here’s the code:
[code=php]
makeVars();
//sendMail();
function makeVars () {
foreach ($_POST as $key => $val) {
$val = stripslashes($val);
echo “$key: $val <br>”;
}
extract($_POST, EXTR_PREFIX_SAME, “a”);
}
That returns a list of variables and their key’s currently, which in a test output as follows:
[code]
request: Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test. Test test test.
ip: ***.0.0.1
firstname: TJ
lastname: ****
email: [email protected]
phone: 123-456-7890
state: AB
regards: Development Services
contact: Email
time: 1187640051718 //To prevent IE caching in AJAX
As you can see the above key’s [i]should
[code=php]
function sendMail() {
if ($regards == “Standard Mail”) {
$address = “$street Apt or Ste:$aptn $city, $state $zip”;
} else {
$address = $state;
}
$subject = $regards;
$message = “nName: $firstname $lastname n
Title: $jobtitlen
Company: $companyn
Email: $emailn
Phone: $phonen
Address: $addressn
Request: n $requestnnn
Extra Info: n
From: $lastname, $firstnamern
Reply-To: $emailrn
Preferred Contact: $contactn
IP address: $ip n”;
echo nl2br($message);
//mail (“postmaster@****.net”, $subject, $message) or die(“Error sending mail!”);
//echo “Your message has been sent successfully. Thanks for your interest in *****, we look forward to being in contact with you.”;
}