Form to mail help

Hi

I wonder anyone you could help, im using the following form to email script but when the email is received with the information and the auto responder email the sender is always nobody and the address [email protected] etc

Would anyone be able to tell me how to mod the script to change this?

Many thanks

<?php /* Set e-mail recipient */ $myemail = "[email protected]"; $subject = "Website Contact Form"; /* Check all form inputs using check_input function */ $name = check_input($_POST['name'], "Name:"); $email_address = check_input($_POST['email_address'], "Email Address:"); $phone_number = check_input($_POST['phone_number'], "Phone Number:"); $message= check_input($_POST['message'], "Message:"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email_address)) { show_error(" The email_address address is not valid. Please click your browsers back button and ensure that email_address address you have entered is valid."); } if (strtolower($_POST['validation']) != 'norfolk') {die('Please click your browser back button and ensure you have entered the validation word correctly.'); } /* Let's prepare the message for the e-mail */ $message = " A contact form has been submitted from midnorfolktrailers.com Name: $name E-mail Address: $email_address Telephone Number: $phone_number Message: $message End of message "; /* Send the message using mail() function */ mail($myemail,$subject,$message); /* Prepare autoresponder subject */ $respond_subject = "Contact Submission"; /* Prepare autoresponder message */ $respond_message = "Thank you for contacting us. We will be in touch shortly. "; /* Send the message using mail() function */ mail($email_address, $respond_subject, $respond_message); /* Redirect visitor to the thank you page */ header('Location: thankyou.html'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?>
<html>
<body>

<b>Please click your browsers back button and correct the following error:</b><br />
<?php echo $myError; ?>

</body>
</html>
<?php exit(); } ?>

having a quick scan through your code i see you don’t include a ‘from’ when using the mail() function.

[php]
$from = ‘[email protected]’;

mail($myemail,$subject,$message, $from); // the $from goes at the end.
[/php]

:wink:

Hello

Thanks for the info, I’ve tried adding the variable but they still seem to come through from the nobody address… Please see the amended code below… Is there anyway of having two separate from emails address - 1 for the auto reply to the customer and 1 to the business?

Thanks for your help in advance.

<?php /* Set e-mail recipient */ $myemail = "[email protected]"; $subject = "Website Contact Form"; /* Check all form inputs using check_input function */ $name = check_input($_POST['name'], "Name:"); $email_address = check_input($_POST['email_address'], "Email Address:"); $phone_number = check_input($_POST['phone_number'], "Phone Number:"); $message= check_input($_POST['message'], "Message:"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email_address)) { show_error(" The email_address address is not valid. Please click your browsers back button and ensure that email_address address you have entered is valid."); } if (strtolower($_POST['validation']) != 'norfolk') {die('Please click your browser back button and ensure you have entered the validation word correctly.'); } /* Let's prepare the message for the e-mail */ $from = "[email protected]"; $message = " A contact form has been submitted Name: $name E-mail Address: $email_address Telephone Number: $phone_number Message: $message End of message "; /* Send the message using mail() function */ mail($myemail,$subject,$message,$from); /* Prepare autoresponder subject */ $respond_subject = "Website Contact"; /* Prepare autoresponder message */ $respond_message = "Thank you for contacting us. We will be in touch shortly. "; /* Send the message using mail() function */ mail($email_address, $respond_subject, $respond_message, $from); /* Redirect visitor to the thank you page */ header('Location: thankyou.html'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?>
<html>
<body>

<b>Please click your browsers back button and correct the following error:</b><br />
<?php echo $myError; ?>

</body>
</html>
<?php exit(); } ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service