Forum Moderators: coopster

Message Too Old, No Replies

Help with sending e-mail form

         

PHPnewbie03

1:09 pm on May 30, 2003 (gmt 0)

10+ Year Member



Hello,
I am very new to PHP (first script)and my isp has told me that the only way for me to send contents of my form is using php... this is what I followed. The form "acts" correctly (once the user hits submit they get redirected to this form.php however, I never get the e-mail... I'm sure I am doing something wrong... can someone help me out please?

<?php
$msg ="First Name:\t$first_name\n";
$msg .="Last Name:\t$last_name\n";
$msg .="Address 1:\t$address_Line_1\n";
$msg .="Address 2:\t$address_Line_2\n";
$msg .="City:\t$city\n";
$msg .="State:\t$state\n";
$msg .="Zip Code:\t$zip\n";
$msg .="Telephone:\t$telephone\n";
$msg .="E-Mail:\t$email\n";
$msg .="Web Site URL:\t$website_url\n";
$msg .="Comments:\t$comments\n\n";

$mailheaders ="From: - Contact Information\n";
$mailheaders = "Reply-To:$email\n\n";

mail("name@domain.com","Feedback Form",$msg,$mailheaders);
?>

Thanks in advance!
Christina

[edited by: jatar_k at 5:22 pm (utc) on May 30, 2003]
[edit reason] removed specific email [/edit]

Birdman

1:56 pm on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello, you are overwriting the first $mailheaders value with the second one because there is no period(.) before the equal(=).

Php.net is a good place to learn about any PHP function. Here is the mail() [us2.php.net] page.

I think if you try something like this, it should work:

<?php
$msg ="First Name:\t$first_name\n";
$msg .="Last Name:\t$last_name\n";
$msg .="Address 1:\t$address_Line_1\n";
$msg .="Address 2:\t$address_Line_2\n";
$msg .="City:\t$city\n";
$msg .="State:\t$state\n";
$msg .="Zip Code:\t$zip\n";
$msg .="Telephone:\t$telephone\n";
$msg .="E-Mail:\t$email\n";
$msg .="Web Site URL:\t$website_url\n";
$msg .="Comments:\t$comments\n\n";
mail("name@domain.com","Feedback Form",$msg,"From: $email\r\n" . "Reply-To: $email\r\n");
?>

I changed the From: value to $email and stuck them right into the mail() function.

ps: Welcome to Webmaster World!

[edited by: jatar_k at 5:23 pm (utc) on May 30, 2003]
[edit reason] removed specific email [/edit]

PHPnewbie03

3:49 pm on May 30, 2003 (gmt 0)

10+ Year Member


Thank you for helping me out! However, sad to say that this still didn't work. Is there anything that I need to place on my actual sendform.html page?
Other than:
<form name="form" method="post" ACTION="form.php" >

I am stumped (did i mention that I'm not a programmer ;o)

Thanks again for the welcome!

Birdman

4:28 pm on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, the first test is to see if the variables were actually sent to the script.

Add this after the mail() line:

print $msg;

If the variables are not printed on the page, you may need to acces your variables using this method:

$_POST['first_name']
$_POST['last_name']
...etc

Or, alternatively, you can extract them all at once like this:

extract($_POST);

If you put that line first in your script, you should be fine.

PHPnewbie03

5:20 pm on May 30, 2003 (gmt 0)

10+ Year Member



ok,
This is my code:
<?php

extract($_POST);

$msg ="First Name:\t$first_name\n";
$msg .="Last Name:\t$last_name\n";
$msg .="Address 1:\t$address_Line_1\n";
$msg .="Address 2:\t$address_Line_2\n";
$msg .="City:\t$city\n";
$msg .="State:\t$state\n";
$msg .="Zip Code:\t$zip\n";
$msg .="Telephone:\t$telephone\n";
$msg .="E-Mail:\t$email\n";
$msg .="Web Site URL:\t$website_url\n";
$msg .="Comments:\t$comments\n\n";
mail("name@domain.com","Feedback Form",$msg,"From: $email\r\n" . "Reply-To: $email\r\n");
print $msg;
?>

This is what happens when the form is submitted:
First Name: Last Name: Address 1: Address 2: City: State: Zip Code: Telephone: E-Mail: Web Site URL: Comments:

I have also tried;
$_POST['first_name'];
$_POST['last_name'];
$_POST['address_line_1'];
$_POST['address_line_2'];
$_POST['city'];
$_POST['state'];
$_POST['zip'];
$_POST['telephone'];
$_POST['email'];
$_POST['website_url'];
$_POST['comments'];
instead of the extract($_POST); with the same results...

Am I still missing something?

[edited by: jatar_k at 5:24 pm (utc) on May 30, 2003]
[edit reason] removed specific email [/edit]

dreamcatcher

5:40 pm on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

Have you tried putting the info in one file instead of passing it to another? ie:

<?php

if($_REQUEST['submit']) {

$msg ="First Name:\t$first_name\n";
$msg .="Last Name:\t$last_name\n";
$msg .="Address 1:\t$address_Line_1\n";
$msg .="Address 2:\t$address_Line_2\n";
$msg .="City:\t$city\n";
$msg .="State:\t$state\n";
$msg .="Zip Code:\t$zip\n";
$msg .="Telephone:\t$telephone\n";
$msg .="E-Mail:\t$email\n";
$msg .="Web Site URL:\t$website_url\n";
$msg .="Comments:\t$comments\n\n";
mail("name@domain.com","Feedback Form",$msg,"From: $email\r\n" . "Reply-To: $email\r\n");

echo "Mail Sent";
exit;

}

?>

Your HTML form would go here. Unless its using echo statements, then it goes before the?>

Your form action would be:

<form method="post" ACTION="<? echo $PHP_SELF;?>">

and assuming your submit button has the attribute:

<input type="submit" name="submit" value="Submit">

:)

[edited by: dreamcatcher at 6:56 pm (utc) on May 30, 2003]

Birdman

6:37 pm on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure that the form field names are exactly the same as the variables you call in the script. If you still don't get the form variables passed to the script, try $HTTP_POST_VARS['email'] instead. It could be that your server is on an old version of PHP.

$msg ="First Name:\t$HTTP_POST_VARS['first_name']\n";
$msg .="Last Name:\t$HTTP_POST_VARS['last_name']\n";
$msg .="Address 1:\t$HTTP_POST_VARS['address_Line_1']\n";
...etc...

PHPnewbie03

7:18 pm on May 30, 2003 (gmt 0)

10+ Year Member



Thank you for trying to help me... but I have done all of your suggestions and still nada...
I really do appreciate all of your time and assistance.. I think I should just give up....

Christina

PHPnewbie03

7:26 pm on May 30, 2003 (gmt 0)

10+ Year Member


GUESS WHAT!

This works (kinda)
<?php

extract($_POST);
$msg = $_POST['first_name'];
$msg .= $_POST['last_name'];
$msg .= $_POST['address_line_1'];
$msg .= $_POST['address_line_2'];
$msg .= $_POST['city'];
$msg .= $_POST['state'];
$msg .= $_POST['zip'];
$msg .= $_POST['telephone'];
$msg .= $_POST['email'];
$msg .= $_POST['website_url'];
$msg .= $_POST['comments'];

mail("name@address.com","Feedback Form",$msg,"From: $email\r\n" . "Reply-To: $email\r\n");
print $msg;
?>

Just a little fomat issue - everything is on one line:
testfirsttestlast123 Main StreetWalt Disney
WorldGA12345508-941-124micky@mouse.orgwww.disney.comtesting 3:23

jatar_k

7:30 pm on May 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you sure your form method is set to post?

You could try something a bit different and much simpler.

$msg = ";
foreach($_POST as $key => $value) {
$msg .= $key . ":\t" . $value . "\n";
}
echo $msg;

another thought would be to try print_r($_POST) [ca.php.net]. That should print out the contents of the post array. If there is nothing in it then it isn't getting passed properly.

What version of php are you using?

PHPnewbie03

11:41 am on Jun 2, 2003 (gmt 0)

10+ Year Member



I actually got this to work - only with everyone's help!

THANK YOU!
I just have to format the e-mail that I receive and things should be ok for now. Again, thank you for all of your help - it is much appreciated!

Happy Day Everyone!