theamazingaustin Posted September 27, 2011 Share Posted September 27, 2011 I apologize in advance, I know pretty much nothing about PHP - don't hate me, please! But I'm working on a form mailer, and it functions, but what I don't like is it leaves all the text fields, blank or not, in my email, which makes it difficult for my client to read, so theres a long list of txt field1: another text field: blah blah: all the way down the email - and I want it gone! haha. I've researched how to do this, but basically, I have no idea how to implement it into my code and don't have time right now to up and learn PHP. My code is as follows: <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'PCI Tour/Excursion Request'; // Your email address. This is where the form information will be sent. $emailadd = 'MY EMAIL HERE'; // Where to redirect after form is processed. $url = 'FORWARDING URL'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> IT was a very simple copy-paste form, but I have no idea what on earth I'm doing. If anyone has any ideas I would GREATLY appriciate the help! Thanks! -Austin Quote Link to comment https://forums.phpfreaks.com/topic/247965-make-form-mail-ignore-empty-text-fields-complete-n00b/ Share on other sites More sharing options...
gizmola Posted September 27, 2011 Share Posted September 27, 2011 I'm not sure what you're asking here. The script is a mess. I stripped out the complete nonsense and am left with this. Give it a try. // Subject of email sent to you. $subject = 'PCI Tour/Excursion Request'; // Your email address. This is where the form information will be sent. $emailadd = 'MY EMAIL HERE'; // Where to redirect after form is processed. $url = 'FORWARDING URL'; $text = "Results from form:\n\n"; foreach ($_POST as $key => $value) { $value = trim(strip_tags($value)); if (!empty($value)) { $text .= "$key: $value\n"; } } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo ''; Quote Link to comment https://forums.phpfreaks.com/topic/247965-make-form-mail-ignore-empty-text-fields-complete-n00b/#findComment-1273303 Share on other sites More sharing options...
theamazingaustin Posted September 27, 2011 Author Share Posted September 27, 2011 I'm not sure what you're asking here. The script is a mess. I stripped out the complete nonsense and am left with this. Give it a try. I really appreciate that! I tried the new form but here is an example email I am getting: Schedule_Jet_Ski: on Zipline_Date: Zipline_Individuals: ziplineInfo: Fishing_Date: Fishing_Individuals: fishingInfo: ATV_Date: ATV_Individuals: atvInfo: Jetski_Date: 09/08/2011 Jet_Ski_Individuals: jetskiInfo: test Sailing_Date: Sailing_Individuals: SailingInfo: Kayak_Date: Kayak_Individuals: kayakingInfo: Adventure_Date: AdvTour_Individuals: adventureTourInfo: Name: Email: Phone: Submit: Submit A few of these I'm making required, but the problem is all these text fields left blank show up in the email and make it such an eye sore for my client. Is there a way to say if the field contains to data to not put it in the email? So I would end up with this instead: Schedule_Jet_Ski: on Jetski_Date: 09/08/2011 Submit: Submit with MUCH less junk. Thanks!! -Austin Quote Link to comment https://forums.phpfreaks.com/topic/247965-make-form-mail-ignore-empty-text-fields-complete-n00b/#findComment-1273314 Share on other sites More sharing options...
gizmola Posted September 27, 2011 Share Posted September 27, 2011 That output is not coming from the script I provided. Quote Link to comment https://forums.phpfreaks.com/topic/247965-make-form-mail-ignore-empty-text-fields-complete-n00b/#findComment-1273322 Share on other sites More sharing options...
theamazingaustin Posted October 1, 2011 Author Share Posted October 1, 2011 That output is not coming from the script I provided. My bad - the page wasn't refreshing the changes to the php, it works beautifully! Thanks SO much! Quote Link to comment https://forums.phpfreaks.com/topic/247965-make-form-mail-ignore-empty-text-fields-complete-n00b/#findComment-1274809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.