Jump to content

LOST emailing a form! Need help badd! thx in advance


siral3x

Recommended Posts

I got the following code:

<?php

@extract($_POST);

$name = stripslashes($name);

$last_name = stripslashes($last_name);

$address = stripslashes($address);

$city = stripslashes($city);

$state = stripslashes($state);

$zip = stripslashes($zip);

$country = stripslashes($country);

$mail = stripslashes($mail);

$tel = stripslashes($tel);

$pen = stripslashes($pen);

$hemp = stripslashes($hemp);

$hbracelet = stripslashes($hbracelet);

$key_chain = stripslashes($key_chain);

$earrings = stripslashes($earrings);

$zipper = stripslashes($zipper);

$s_beads = stripslashes($s_beads);

 

mail('[email protected],$name,$last_name,$address,$city,$state,$zip,$country,$mail,$tel,$pen,$hemp,$hbracelet,$key_chain,$earrings,$zipper,$s_beads, "From: $name <$mail>");

header("location:form.php");

?>

 

IS THIS going to work?? I mean, am I going to recive all the info in those fields or not??

I'm lost...I'm not sure if I'm on the right track.

thx

Alex

No, that is not going to work. The mail() function takes at most 5 parameters:

1) To

2) Subject

3) Body

4) Additional headers (optional, but really should be used to set the From address)

5) Additional parameters (rarely used by most people)

 

See the manual page for the function.

 

The simplest way of getting the results you want is:

<?php
$to = "[email protected]",
$subject = "Put your subject line here";
$tmp = array();
foreach($_POST as $fld => $val)
    if ($fld != 'submit') // or whatever your submit button is named
        $tmp[] = $fld . ': ' . stripslashes($val);
$body = implode("\r\n",$tmp) . "\r\n";
$headers = 'From: ' . $name . ' <' . $mail . '>'; // doing this can be very dangerous and can open your form up to spammers
mail($to,$subject,$body,$headers);
?>

 

Ken

This section:

<?php
foreach($_POST as $fld => $val)
    if ($fld != 'submit') // or whatever your submit button is named
        $tmp[] = $fld . ': ' . stripslashes($val);
?>

adds all the fields in the $_POST array into a temporary array.

And this line:

<?php
$body = implode("\r\n",$tmp) . "\r\n";
?>

puts all of them into the $body variable with a newline after each.

 

Ken

SO I need like :

 

foreach($_POST as $fld => $name)

    if ($fld != 'submit') // or whatever your submit button is named

        $tmp[] = $fld . ': ' . stripslashes($name);

 

foreach($_POST as $fld => $last_name)

    if ($fld != 'submit') // or whatever your submit button is named

        $tmp[] = $fld . ': ' . stripslashes($last_name);

 

foreach($_POST as $fld => $address)

    if ($fld != 'submit') // or whatever your submit button is named

        $tmp[] = $fld . ': ' . stripslashes($address);

 

etc..

etc..

CORRECT???

 

Then :

 

$body = implode("\r\n",$tmp) . "\r\n";

$headers = 'From: ' . $name . ' <' . $mail . '>';

mail($to,$subject,$body,$headers);

 

And that's it??

Sorry for all these questions, but I'm very new to php.

 

 

 

 

 

 

No you will only need to call this once, it will go through every vaiable until all are put into the array and ready for sending:

 

foreach($_POST as $fld => $val)

    if ($fld != 'submit') // or whatever your submit button is named

        $tmp[] = $fld . ': ' . stripslashes($val);

 

The foreach really does mean foreach, whether it is 1 or 100 variable items, they will all be input with that simple code.

"they will all be imput" is all I needed to know!!!

My process.php file should look like this???? :

 

<?php

@extract($_POST);

$name = stripslashes($name);

$last_name = stripslashes($last_name);

$address = stripslashes($address);

$city = stripslashes($city);

$state = stripslashes($state);

$zip = stripslashes($zip);

$country = stripslashes($country);

$mail = stripslashes($mail);

$tel = stripslashes($tel);

$pen = stripslashes($pen);

$hemp = stripslashes($hemp);

$hbracelet = stripslashes($hbracelet);

$key_chain = stripslashes($key_chain);

$earrings = stripslashes($earrings);

$zipper = stripslashes($zipper);

$s_beads = stripslashes($s_beads);

 

$to = "[email protected]",

$subject = "Put your subject line here";

$tmp = array();

foreach($_POST as $fld => $val)

    if ($fld != 'submit')

        $tmp[] = $fld . ': ' . stripslashes($val);

$body = implode("\r\n",$tmp) . "\r\n";

$headers = 'From: ' . $name . ' <' . $mail . '>';

mail($to,$subject,$body,$headers);

?>

 

Did I got it right? OR I don't have to declare all the var??? It will auto imput them?

 

 

No.

 

You're entire process.php file should look like:

<?php
$to = "[email protected]",
$subject = "Put your subject line here";
$tmp = array();
foreach($_POST as $fld => $val)
    if ($fld != 'submit')
        $tmp[] = $fld . ': ' . stripslashes($val);
$body = implode("\r\n",$tmp) . "\r\n";
$headers = 'From: ' . $name . ' <' . $mail . '>';
mail($to,$subject,$body,$headers);
?>

 

Putting all the values into separate variables is just more work for you that is not needed.

 

Ken

  • 4 weeks later...

code  for "process.php" :

<?php

$to = "[email protected]"

$subject = "Put your subject line here";

$tmp = array();

foreach($_POST as $fld => $val)

    if ($fld != 'submit')

        $tmp[] = $fld . ': ' . stripslashes($val);

$body = implode("\r\n",$tmp) . "\r\n";

$headers = 'From: ' . $name . ' <' . $mail . '>';

mail($to,$subject,$body,$headers);

echo "<h5>YOUR REQUEST HAS BEEN SENT! WE WILL GET BACK TO YOU SOON!</h5>";

?>

 

 

"Parse error: parse error, unexpected T_VARIABLE in /process.php"

I don't get it, it worked fine with my php version...now I uploaded the files on the web hosting server and I get this error???

What to do??

thx

Alex

OK, I'm DESPERATE, I get no errors but the date won't be emailed at all

I have 2 files: form.html and process.php

form.html

<form action="process.php" method="post">
<table border=1>
<tr>
<tr>
<td>First name:</td>
<td align="center"><input type="text" name="$name" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Last name:</td>
<td align="center"><input type="text" name="$last_name" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Address:</td>
<td align="center"><input type="text" name="$address" size="15" maxlength="30"></td>
</tr>
<tr>
<td>City:</td>
<td align="center"><input type="text" name="$city" size="15" maxlength="30"></td>
</tr>
<tr>
<td>State:</td>
<td align="center"><input type="text" name="$state" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Postal Code:</td>
<td align="center"><input type="text" name="$zip" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Country:</td>
<td align="center"><input type="text" name="$country" size="15" maxlength="30"></td>
</tr>
<tr>
<td>E-mail:</td>
<td align="center"><input type="text" name="$mail" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Telephone:</td>
<td align="center"><input type="text" name="$tel" size="15" maxlength="30"></td>
</tr>
</table>

 

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

then I have process.php

<?php
$to = "[email protected]";
$subject = "Put your subject line here";
$tmp = array();
foreach($_POST as $fld => $val)
    if ($fld != 'submit')
        $tmp[] = $fld . ': ' . stripslashes($val);
$body = implode("\r\n",$tmp) . "\r\n";
$headers = 'From: ' . $_POST['name'] . ' <' . $_POST['mail'] . '>';
mail($to,$subject,$body,$headers);
echo "<h5>YOUR REQUEST HAS BEEN SENT! WE WILL GET BACK TO YOU SOON!</h5>";
?>

 

I receive no errors but nothing works..I don't receive the email with the collected data.

NOW what??

THX in advance

ALEX

OOPPSSS the code for form.html is:

<form action="process.php" method="post">
<table border=1>
<tr>
<tr>
<td>First name:</td>
<td align="center"><input type="text" name="name" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Last name:</td>
<td align="center"><input type="text" name="last_name" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Address:</td>
<td align="center"><input type="text" name="address" size="15" maxlength="30"></td>
</tr>
<tr>
<td>City:</td>
<td align="center"><input type="text" name="city" size="15" maxlength="30"></td>
</tr>
<tr>
<td>State:</td>
<td align="center"><input type="text" name="state" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Postal Code:</td>
<td align="center"><input type="text" name="zip" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Country:</td>
<td align="center"><input type="text" name="country" size="15" maxlength="30"></td>
</tr>
<tr>
<td>E-mail:</td>
<td align="center"><input type="text" name="mail" size="15" maxlength="30"></td>
</tr>
<tr>
<td>Telephone:</td>
<td align="center"><input type="text" name="tel" size="15" maxlength="30"></td>
</tr>
</table>
<div align="center"><center><table border="0"
            width="480">
                <tr>
                    <td align="center"><input type="submit"
                    value="Submit Order"></td>
                    <td align="center"><input type="reset"
                    value="Reset form"></td>
                </tr>
            </table>
            </center></div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.