siral3x Posted April 18, 2007 Share Posted April 18, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/ Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231821 Share on other sites More sharing options...
siral3x Posted April 18, 2007 Author Share Posted April 18, 2007 In your example where do I add the extra $Last_name,$address, $city variables to mail them??? or how do I mail all those vars? thx a lot!!! Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231853 Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231870 Share on other sites More sharing options...
siral3x Posted April 18, 2007 Author Share Posted April 18, 2007 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. Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231876 Share on other sites More sharing options...
rcorlew Posted April 18, 2007 Share Posted April 18, 2007 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. Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231878 Share on other sites More sharing options...
siral3x Posted April 18, 2007 Author Share Posted April 18, 2007 "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? Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231883 Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231887 Share on other sites More sharing options...
siral3x Posted April 18, 2007 Author Share Posted April 18, 2007 Parse error: parse error in c:\program files\easyphp1-8\www\process.php on line 2 Line 2 would be: $to = "[email protected]", Is it because I don't have sendmail installed? Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231892 Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 Replace the ending comma with a semi-colon. Ken Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231894 Share on other sites More sharing options...
siral3x Posted April 18, 2007 Author Share Posted April 18, 2007 Ha, I noticed that it's 1 AM here line 9: $headers = 'From: ' . $name . ' <' . $mail . '>'; Undefined variable: name Undefined variable: mail This one I'm clueless Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231898 Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 Sorry, I'm half asleep also ... Change to: <?php $headers = 'From: ' . $_POST['name'] . ' <' . $_POST['mail'] . '>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231900 Share on other sites More sharing options...
siral3x Posted April 18, 2007 Author Share Posted April 18, 2007 Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your YEP...I need sendmail for sure!!! I"M ALL SET!! THX A LOT KEN!!! This forum is awesome! Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-231903 Share on other sites More sharing options...
siral3x Posted May 13, 2007 Author Share Posted May 13, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-251764 Share on other sites More sharing options...
siral3x Posted May 13, 2007 Author Share Posted May 13, 2007 ok...apparently I was missing a semi colon Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-251782 Share on other sites More sharing options...
siral3x Posted May 14, 2007 Author Share Posted May 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-252511 Share on other sites More sharing options...
siral3x Posted May 14, 2007 Author Share Posted May 14, 2007 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> Link to comment https://forums.phpfreaks.com/topic/47499-lost-emailing-a-form-need-help-badd-thx-in-advance/#findComment-252526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.