View Full Version : mail form with headers problem

03-20-2010, 02:53 PM
hi i got this mail form that works but i got some problems with i get the mail sent to my email but in the mail it dont show the email submitted by the user from the form but my own mail.

can somebody tell me how the headers should bset in the code to
send the email to my mailbox showing the email set by the user
i also wonder if its possible to add a functin for sending acopy of the mail
to the user
/ thanks Lisa
the code
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

//Validate first
echo "Name and email are mandatory!";

echo "Bad email value!";

$email_from = 'yourname@yoursite.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".

$to = "your@email.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
//done. redirect to thank-you page.
header('Location: thank-you.html');

// Function to validate against any email injection attempts
function IsInjected($str)
$injections = array('(\n+)',
$inject = join('|', $injections);
$inject = "/$inject/i";
return true;
return false;


03-20-2010, 03:15 PM
Change this

$email_from = 'yourname@yoursite.com';//<== update the email address

to this

$email_from = "$otheremail";//<== update the email address

Then in your form that you type in the information (which isn't listed in that code) change it to this

<input type="text" name="otheremail">

03-20-2010, 03:21 PM
thanks alot ollie, do you know how to send a copy to the user to?

03-20-2010, 05:14 PM
You're welcome, I don't but you can try this, it seems like it might work.

$to = "your@email.com";//<== update the email address
$to = "their@email.com";//<== update the email address

Also option 2.

You could do in 2 send mail forms, the first to send to you, and the second to send to them with a different message. You can use the same variables.

03-20-2010, 05:30 PM
i tried changing email from to $other email but it dont work, when recieving the email it shows from $other in the from field in the email client.

03-20-2010, 06:16 PM
Sorry I should have been a little clearer. You need to change the form. The textbox that they enter their name into. That name needs to be "otheremail" then when the form is submitted you need to extract into a variable.

Like this

$otheremail = $_POST['otheremail'];

03-20-2010, 06:30 PM
i changed it in both the form and the php page but dont work

03-20-2010, 11:54 PM
Post the whole script so I can see whats causing it the problem.

03-24-2010, 03:23 AM
try doing this:

take out this:
$email_from = 'yourname@yoursite.com';//<== update the email address

and put your header

$headers = "From: $email_from \r\n";
to this:

$headers = "From: ".$_POST["email"]."\r\n"

I'm still learning, forgive me if it doesnt work :-)

03-24-2010, 03:42 AM
Everything your asking for is on here:- http://php.net/manual/en/function.mail.php

and to send to more than one person just do this:

$to = 'email1@email.com';
$to .= 'email2@email.com';
$to .= 'email3@email.com';

03-24-2010, 11:22 PM
I realize this post was abandoned a few days ago, but this should be addressed:

and to send to more than one person just do this:

$to = 'email1@email.com';
$to .= 'email2@email.com';
$to .= 'email3@email.com';

No. All you've done there is create a long and bad email address. They would at least need to be comma separated.

$to = 'email1@example.com';
$to .= ',email2@example.com';
$to .= ',email3@example.com';

Using additional headers would be another solution.

03-24-2010, 11:38 PM
Everything given will work, just need to see the whole script so we can see where the placement error is.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum