Page 1 of 1

My form is sending but- the "sender" is APACHE - pleasehelp

Posted: Tue Dec 02, 2008 6:20 pm
by kitegirl
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi there - I have looked around these forums for help but can't find exactly what I am looking for. I would really appreciate some help here and my apologies if this is elsewhere.

I am new to PHP - but am doing ok. I have set up a test form for a clients website and the form is working perfectly. Collecting the data and emailing it to my email address. But all the emails are coming "from" - APACHE. How do I get the user's email into the "from" field.

Cheers
Katie

Here is my test code:

Code: Select all

<?php
/* Set e-mail recipient */
$myemail  = "****@yahoo.com";
 
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject  = check_input($_POST['subject'], "Write a subject");
$email    = check_input($_POST['email']);
$website  = check_input($_POST['website']);
$likeit   = check_input($_POST['likeit']);
$how_find = check_input($_POST['how']);
$from = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your comments");
 
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("E-mail address not valid");
}
 
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
    $website = '';
}
 
/* Let's prepare the message for the e-mail */
$message = "Hello!
 
Your contact form has been submitted by:
 
Name: $yourname
E-mail: $email
URL: $website
 
Like the website? $likeit
How did he/she find it? $how_find
 
Comments:
$comments
 
End of message
";
 
/* Send the message using mail() function */
mail($myemail, $subject, $message, $from);
 
/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
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 correct the following error:</b><br />
    <?php echo $myError; ?>
 
    </body>
    </html>
<?php
exit();
}
?>

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: My form is sending but- the "sender" is APACHE - pleasehelp

Posted: Tue Dec 02, 2008 7:14 pm
by requinix

Code: Select all

/* Send the message using mail() function */
mail($myemail, $subject, $message, $from);
The fourth argument to mail - $from - isn't correct. Try

Code: Select all

/* Send the message using mail() function */
mail($myemail, $subject, $message, "From: $from");
instead.

Take a look at this page, what it says about "additional_headers", the examples, and the user comments.

Re: My form is sending but- the "sender" is APACHE - pleasehelp

Posted: Tue Dec 02, 2008 7:27 pm
by kitegirl
Hi tasairls
You are top notch. That worked a treat - too easy. It's been driving me nuts. Thankyou so MUCH.

Cheers
K

Re: My form is sending but- the "sender" is APACHE - pleasehelp

Posted: Wed Dec 03, 2008 10:04 am
by pickle
I anonymized your email address in your code so you don't get lamb basted with SPAM.