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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kitegirl
Forum Newbie
Posts: 9
Joined: Tue Dec 02, 2008 6:07 pm

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

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
kitegirl
Forum Newbie
Posts: 9
Joined: Tue Dec 02, 2008 6:07 pm

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

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post by pickle »

I anonymized your email address in your code so you don't get lamb basted with SPAM.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply