A tip I use is to set the From field to an e-mail address of my choice. Such as "customerqueries@mydomain.com".
Now, you would still have the e-mail input in the form (incase the person who filled it in needs a reply) so you just append/add the entered e-mail address to the $message variable.
And I see you sometimes receive empty e-mails. Well this is easily fixed.
What you can do is trim the fileds (trim() removes any surplus spaces in a string) and then check the length of the fileds. Note: The fields that you do not want to be empty should be indicated with an asterix (*) or other symbol on the effect and with explanatory text stating what the * or other symbol means.
With that in mind, your code would look something like this.
PHP Code:
<?php $sendTo = "contact@mywebsite.org"; $subject = "Contact Request";
// variables are sent to this PHP page through // the POST method. $_POST is a global associative array // of variables passed through this method. From that, we // can get the values sent to this page from Flash and // assign them to appropriate variables which can be used // in the PHP mail() function.
// I assume there is 3 fields // name, email and message
$errors = 0;
if(strlen(trim($_POST['name']) == 0)) { $errors = $errors + 1; } if(strlen(trim($_POST['email']) == 0)) { $errors = $errors + 1; } if(strlen(trim($_POST['message']) == 0)) { $errors = $errors + 1; }
if($errors == 0) { // Send email)
$headers = "From: Customer Query <customer-query@mydomain.com>\r\n"; $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; $headers .= "Return-path: " . $_POST["email"];
// content of the message to a body variable $message="name: ".$name." email: ".$email." phone: ".$phone." comments: ".$comments." ";
// once the variables have been defined, they can be included // in the mail function call which will send you an email mail($sendTo, $subject, $message, $headers); header("Refresh: 0;url=http://www.mywebsite.org/thankyou.html"); } ?>
Note that this is untested and there are some more possible improvements. I thought I posted a tutorial about this but cannot seem to find it. There are however lots and lots of tutorials on handling PHP email so google is your friend.
|