PDA

View Full Version : php "from" problem


dazzclub
09-13-2007, 10:21 AM
Hi guys,

I am working the original php contact form so i can have a bcc as well as sending it to the main person.

However i`ve come across a problem where by it says "From: drinkpro@server11.kthosting.com" when i check my emails.

i awat of why i am getting it but i cant seem to capture the users email and pass that through to the "from" part of the emial.

my code is below
-------------

<?php
if(isset($_POST['submit'])) {

$to = "myemail@hotmail.com";
$headers .= "CC: mayemail@yahoo.co.uk\r\n";
$EmailFrom = Trim(stripslashes($_POST['email_field']));
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];


$body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";

echo "Data has been submitted to $to!";
mail($to, $subject, $body, $headers, $EmailFrom);

} else {
echo "blarg!";
}
?>
--------------

cheers

davidj
09-15-2007, 05:45 PM
please explain abit clearer

dazzclub
09-19-2007, 10:07 AM
lol, sorry for that. Ok here goes.

I would like to add an additional recipient to this form. IT currently goes to my own email, however i would like to cc someone in on it aswell.

I have managed to do that however, when i test the form, rather than having the persons email (the person who is using the form) appear in the "from" section it displays "drinkpro@server11.kthosting.com"

How can i sort it out so it shows the persons email to be in the from section?

Here is a link to the image that may hopefully explain it a bit clearer as well

http://www.drinkpromo.com/contactfrom-question.jpg

davidj
09-19-2007, 11:00 AM
<?php
if(isset($_POST['submit'])) {

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Me<myemail@hotmail.com>' . "\r\n";
$headers .= "From:".Trim(stripslashes($_POST['email_field'])). "\r\n";
$headers .= 'Cc: whever@example.com' . "\r\n";
$headers .= 'Bcc: whoever@example.com' . "\r\n";


$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field .= $_POST['email'];
$message = $_POST['message'];

/// not sure about this. I would have use sprintf
$body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";

echo "Data has been submitted to $to!";
mail($to, $subject, $body, $headers);

} else {
echo "blarg!";
}
?>

--------------

dazzclub
09-19-2007, 02:52 PM
thanks for that

davidj
09-19-2007, 02:56 PM
made a correction so try again if you have copied it

dazzclub
09-19-2007, 03:05 PM
May i ask you a quick question? How can i post an immediate Thank you to notify the user the form has been sent. In the past i have been creating a separate thank you page.

What i would like to happen is the user to submit the form and somewhere still in the contact box or even close to the submit button, a message to pop up displaying "Thank you for completing the form" so it happens on the same page.

Any good tuts on this subject matter?

Thanks again for your help

davidj
09-19-2007, 03:10 PM
do you understand PHP

dazzclub
09-28-2007, 10:22 AM
umm....just a little, i sometimes get too slack and use existing code to achieve what i want which is a bit stupid really as i need to get to grips with it