lou28 Posted October 9, 2008 Share Posted October 9, 2008 Hi, I have a form 3 fields in it and I am using this php code to process the form: <?php $sender = $_POST["email"]; $sentfrom = "From: $sender"; $to = '[email protected]'; $name = $_POST["name"]; $text = $_POST["message"]; if(($sender=='')||($to=='')||($name=='')||($text=='')) { echo "<center><b>Please make sure you complete the form</b></center>"; } else { if(mail($to, $name, $text, $sentfrom, '-f'.$sender)) { echo "<center><b>Thank you for your enquiry, someone will respond to you as soon as possible.</b></center>"; } else { echo "<center><b>Sorry, your email cannot be sent right now</b></center>"; } } ?> However I want to add more fields but if I do I get an error returned telling me I can't have more than 5 variables in the 'mail' bit. If there a way to work around this? I am a php beginner and have tried everything I can think of! Thanks Link to comment https://forums.phpfreaks.com/topic/127677-limit-of-5-variables-need-to-add-more-please-help/ Share on other sites More sharing options...
JasonLewis Posted October 9, 2008 Share Posted October 9, 2008 What other variables do you want to add? You can build the body out of many variables. Like so: $text = $_POST['message']; $firstname = $_POST['first_name']; $dob = $_POST['dob']; $body = <<<html First Name: {$firstname}\n Birthday: {$dob}\n\n Message:\n {$text} html; Then use $body in the place of $text in your mail() function. Hope that makes sense. Link to comment https://forums.phpfreaks.com/topic/127677-limit-of-5-variables-need-to-add-more-please-help/#findComment-660762 Share on other sites More sharing options...
lou28 Posted October 9, 2008 Author Share Posted October 9, 2008 Thanks for that, I have tried it, but I'm not receiving the email. No error comes up at all so I can't understand why. Do you have any ideas? <?php $sender = $_POST["email"]; $sentfrom = "From: $sender"; $to = '[email protected]'; $name = $_POST["name"]; $companyname = $_POST["companyname"]; $telephone = $_POST["telephone"]; $text = $_POST["enquiry"]; $body = <<<html Name: {$name}\n Telephone: {$telephone}\n Company Name: {$companyname}\n\n Message:\n {$text} html; if(($sender=='')) { echo "<center><b>Please make sure you complete the form</b></center>"; } else { if(mail($to, $body, '-f'.$sender)) { echo "<center><b>Thank you for your enquiry, someone will respond to you as soon as possible.</b></center>"; } else { echo "<center><b>Sorry, your email cannot be sent right now</b></center>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/127677-limit-of-5-variables-need-to-add-more-please-help/#findComment-660800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.