Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-20-2010, 01:53 PM   PM User | #1
danielandlisa
New Coder

 
Join Date: Dec 2009
Posts: 24
Thanks: 2
Thanked 0 Times in 0 Posts
danielandlisa is an unknown quantity at this point
mail form with headers problem

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
<?php
if(!isset($_POST['submit']))
{
//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
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}

if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}

$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!
mail($to,$email_subject,$email_body,$headers);
//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+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?>
danielandlisa is offline   Reply With Quote
Old 03-20-2010, 02:15 PM   PM User | #2
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Change this

PHP Code:
$email_from 'yourname@yoursite.com';//<== update the email address 
to this

PHP Code:
$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

PHP Code:
<input type="text" name="otheremail"
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Old 03-20-2010, 02:21 PM   PM User | #3
danielandlisa
New Coder

 
Join Date: Dec 2009
Posts: 24
Thanks: 2
Thanked 0 Times in 0 Posts
danielandlisa is an unknown quantity at this point
thanks alot ollie, do you know how to send a copy to the user to?
danielandlisa is offline   Reply With Quote
Old 03-20-2010, 04:14 PM   PM User | #4
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
You're welcome, I don't but you can try this, it seems like it might work.

PHP Code:
$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.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

Last edited by masterofollies; 03-20-2010 at 04:16 PM..
masterofollies is offline   Reply With Quote
Old 03-20-2010, 04:30 PM   PM User | #5
danielandlisa
New Coder

 
Join Date: Dec 2009
Posts: 24
Thanks: 2
Thanked 0 Times in 0 Posts
danielandlisa is an unknown quantity at this point
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.
danielandlisa is offline   Reply With Quote
Old 03-20-2010, 05:16 PM   PM User | #6
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
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

PHP Code:
$otheremail $_POST['otheremail']; 
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Old 03-20-2010, 05:30 PM   PM User | #7
danielandlisa
New Coder

 
Join Date: Dec 2009
Posts: 24
Thanks: 2
Thanked 0 Times in 0 Posts
danielandlisa is an unknown quantity at this point
i changed it in both the form and the php page but dont work
danielandlisa is offline   Reply With Quote
Old 03-20-2010, 10:54 PM   PM User | #8
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Post the whole script so I can see whats causing it the problem.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Old 03-24-2010, 02:23 AM   PM User | #9
happeemom
New Coder

 
Join Date: Mar 2010
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
happeemom is an unknown quantity at this point
try doing this:

take out this:
Code:
$email_from = 'yourname@yoursite.com';//<== update the email address
and put your header
Code:
$headers = "From: $email_from \r\n";
to this:
Code:
$headers = "From: ".$_POST["email"]."\r\n"
I'm still learning, forgive me if it doesnt work :-)
happeemom is offline   Reply With Quote
Old 03-24-2010, 02:42 AM   PM User | #10
DJCMBear
Senior Coder

 
DJCMBear's Avatar
 
Join Date: Mar 2010
Location: United Kindom
Posts: 1,173
Thanks: 14
Thanked 136 Times in 136 Posts
DJCMBear is on a distinguished road
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:
PHP Code:
$to  'email1@email.com';
$to .= 'email2@email.com';
$to .= 'email3@email.com'
DJCMBear is offline   Reply With Quote
Old 03-24-2010, 10:22 PM   PM User | #11
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
I realize this post was abandoned a few days ago, but this should be addressed:
Quote:
Originally Posted by DJCMBear View Post
and to send to more than one person just do this:
PHP Code:
$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.
PHP Code:
$to  'email1@example.com';
$to .= ',email2@example.com';
$to .= ',email3@example.com'
Using additional headers would be another solution.
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 03-24-2010, 10:38 PM   PM User | #12
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Everything given will work, just need to see the whole script so we can see where the placement error is.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:09 AM.


Advertisement
Log in to turn off these ads.