bukwus Posted April 19, 2012 Share Posted April 19, 2012 Hi I'm working on a form that, when submitted via POST, the info goes to a separate PHP file for processing and then returns to the form page. Pretty standard stuff. Everything is working, except, when it sends an email via the mail() function, the first SESSION (containing what the user selected for "Country") works fine, but the second (which is supposed to contain what they selected for "Best Time to Call") will only display "Array" in the email. Here's the form, sorry for the huge arrays: <?php session_start(); // SET ARRAYS $countriesNum = 237; $countries = array(1 => 'United States','United Kingdom','Canada','Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antarctica','Antigua & Barbuda','Argentina','Armenia','Aruba','Ascension Islands','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia & Herzegowina','Botswana','Bouvet Island','Brazil','British Indian Ocean Territory','Brunei','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Cocos (Keeling) Islands','Colombia','Comoros','Congo, Dem. Rep. of the','Congo, Rep. of the','Cook Islands','Costa Rica','Côte d\'Ivoire','Croatia','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','French Southern Territories','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey','Guinea','Guinea-Bissau','Guyana','Haiti','Heard & Mc Donald Islands','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iraq','Ireland','Isle of Man','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea, South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russia','Rwanda','Saint Helena','Saint Kitts & Nevis','Saint Lucia','Saint Pierre & Miquelon','Saint Vincent & the Grenadines','Samoa','San Marino','Sao Tome & Principe','Saudi Arabia','Senegal','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','So. Georgia & So. Sandwich Is.','Solomon Islands','Somalia','South Africa','Spain','Sri Lanka','Suriname','Svalbard & Jan Mayen Islands','Swaziland','Sweden','Switzerland','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad & Tobago','Tunisia','Turkey','Turkmenistan','Turks & Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United States Minor Outlying Is.','Uruguay','Uzbekistan','Vanuatu','Vatican City','Venezuela','Vietnam','Virgin Islands (British)','Virgin Islands (U.S.)','Wallis & Futuna Islands','Western Sahara','Yemen','Yugoslavia','Zambia','Zimbabwe'); $countryAbrv = array(1 => 'USA','GBR','CAN','AFG','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','ASC','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','CD','COG','COK','CRI','CIV','HRV','CYP','CZE','DNK','DJI','DMA','DOM','TMP','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','ATF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GG','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IDN','IRQ','IRL','IM','ISR','ITA','JAM','JPN','JE','JOR','KAZ','KEN','KIR','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROM','RUS','RWA','SHN','KNA','LCA','SPM','VCT','WSM','SMR','STP','SAU','SEN','SYC','SLE','SGP','SVK','SVN','SGS','SLB','SOM','ZAF','ESP','LKA','SUR','SJM','SWZ','SWE','CHE','TWN','TJK','TZA','THA','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','YUG','ZMB','ZWE'); $callTimeNum = 4; $callTimeAbrv = array(1 => 'any','morn','noon','eve'); $callTime = array(1 => 'Anytime','Morning','Afternoon','Evening'); ?> <form id="formIF" action="form-test-engine.php" method="POST"> <table> <tr> <td width="35%"> <label for="country">Country</label> </td> <td width="65%"> <select name="country" class="textIF"> <?php for ($i = 1; $i <= $countriesNum; $i++) { echo'<option '.$_SESSION['chkCountry'.$i].' value="'.$countryAbrv[$i].'">'.$countries[$i].'</option>'; unset($_SESSION['chkCountry'.$i]); } ?> </select> </td> </tr> <tr> <td> <label for="callTime">Best Time to Call</label> </td> <td> <select name="callTime" class="textIF"> <?php for ($i = 1; $i <= $callTimeNum; $i++) { echo'<option '.$_SESSION['chkCallTime'.$i].' value="'.$callTimeAbrv[$i].'">'.$callTime[$i].'</option>'; unset($_SESSION['chkCallTime'.$i]); } ?> </select> </td> </tr> <tr> <td colspan="2" id="submitIF"> <input type="submit" name="submit" value="Submit" /> <input type="submit" name="submitReset" value="Reset Form" /> </td> </tr> </table> </form> </p> <?php if ($_SESSION['process'] == 'yes') { $to = "[email protected]"; $email_subject = "Info request from Interface Financial Group on Buzgate"; $email_body = "Country: ".$_SESSION['country']."\n Best time to call: ".$_SESSION['callTime']."\n"; $headers = "From: [email protected]"; mail($to, $email_subject, $email_body, $headers); } $_SESSION['process'] = 'no'; ?> Here's the processing file: <?php session_start(); // CHECK IF RESET OR SUBMIT BUTTON WAS SELECTED if (isset($_POST['submitReset'])) { session_destroy(); $_SESSION['process'] = 'no'; } elseIf (isset($_POST['submit'])) { // SET ARRAYS $countriesNum = 237; $countries = array(1 => 'United States','United Kingdom','Canada','Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antarctica','Antigua & Barbuda','Argentina','Armenia','Aruba','Ascension Islands','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia & Herzegowina','Botswana','Bouvet Island','Brazil','British Indian Ocean Territory','Brunei','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Cocos (Keeling) Islands','Colombia','Comoros','Congo, Dem. Rep. of the','Congo, Rep. of the','Cook Islands','Costa Rica','Côte d\'Ivoire','Croatia','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','French Southern Territories','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey','Guinea','Guinea-Bissau','Guyana','Haiti','Heard & Mc Donald Islands','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iraq','Ireland','Isle of Man','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea, South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russia','Rwanda','Saint Helena','Saint Kitts & Nevis','Saint Lucia','Saint Pierre & Miquelon','Saint Vincent & the Grenadines','Samoa','San Marino','Sao Tome & Principe','Saudi Arabia','Senegal','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','So. Georgia & So. Sandwich Is.','Solomon Islands','Somalia','South Africa','Spain','Sri Lanka','Suriname','Svalbard & Jan Mayen Islands','Swaziland','Sweden','Switzerland','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad & Tobago','Tunisia','Turkey','Turkmenistan','Turks & Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United States Minor Outlying Is.','Uruguay','Uzbekistan','Vanuatu','Vatican City','Venezuela','Vietnam','Virgin Islands (British)','Virgin Islands (U.S.)','Wallis & Futuna Islands','Western Sahara','Yemen','Yugoslavia','Zambia','Zimbabwe'); $countryAbrv = array(1 => 'USA','GBR','CAN','AFG','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','ASC','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','CD','COG','COK','CRI','CIV','HRV','CYP','CZE','DNK','DJI','DMA','DOM','TMP','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','ATF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GG','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IDN','IRQ','IRL','IM','ISR','ITA','JAM','JPN','JE','JOR','KAZ','KEN','KIR','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROM','RUS','RWA','SHN','KNA','LCA','SPM','VCT','WSM','SMR','STP','SAU','SEN','SYC','SLE','SGP','SVK','SVN','SGS','SLB','SOM','ZAF','ESP','LKA','SUR','SJM','SWZ','SWE','CHE','TWN','TJK','TZA','THA','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','YUG','ZMB','ZWE'); $callTimeNum = 4; $callTimeAbrv = array(1 => 'any','morn','noon','eve'); $callTime = array(1 => 'Anytime','Morning','Afternoon','Evening'); // SET SESSIONS if(isset($_POST['country'])) { for ($i = 1; $i <= $countriesNum; $i++) { if ($_POST['country'] == $countryAbrv[$i]) { $_SESSION['chkCountry'.$i] = 'selected="selected"'; $_SESSION['country'] = $countries[$i]; } } } if(isset($_POST['callTime'])) { for ($i = 1; $i <= $callTimeNum; $i++) { if ($_POST['callTime'] == $callTimeAbrv[$i]) { $_SESSION['chkCallTime'.$i] = 'selected="selected"'; $_SESSION['callTime'] = $callTime[$i]; } } } $_SESSION['process'] = 'yes'; } header('Location: form-test.php'); ?> And here's an example of the resulting email content: Country: American Samoa Best time to call: Array Quote Link to comment https://forums.phpfreaks.com/topic/261270-sessions-in-mail-function-failing/ Share on other sites More sharing options...
tipsmail7 Posted April 19, 2012 Share Posted April 19, 2012 It's strange When I copy that code and try it my apache, the email body was expected (not an 'Array' word) result in my email: ============================== Subject: Info request from Interface Financial Group on Buzgate X-PHP-Originating-Script: 0:form-test.php From: [email protected] Country: Antarctica Best time to call: Evening ============================== Quote Link to comment https://forums.phpfreaks.com/topic/261270-sessions-in-mail-function-failing/#findComment-1338877 Share on other sites More sharing options...
bukwus Posted April 19, 2012 Author Share Posted April 19, 2012 It's strange When I copy that code and try it my apache, the email body was expected (not an 'Array' word) Crap! I just don't get it. Quote Link to comment https://forums.phpfreaks.com/topic/261270-sessions-in-mail-function-failing/#findComment-1338878 Share on other sites More sharing options...
tipsmail7 Posted April 20, 2012 Share Posted April 20, 2012 It's strange When I copy that code and try it my apache, the email body was expected (not an 'Array' word) Crap! I just don't get it. Well, I 'run' that form in my web server, and it produces an expected mail, e.g., it writes Best time to call: Evening not Best time to call: Array. So why your email-result is not same as my email-result? *sorry if you don't understand my English. Or maybe I just don't understand your question? Quote Link to comment https://forums.phpfreaks.com/topic/261270-sessions-in-mail-function-failing/#findComment-1338942 Share on other sites More sharing options...
bukwus Posted April 23, 2012 Author Share Posted April 23, 2012 Well, I 'run' that form in my web server, and it produces an expected mail, e.g., it writes Best time to call: Evening not Best time to call: Array. So why your email-result is not same as my email-result? *sorry if you don't understand my English. Or maybe I just don't understand your question? No, I understand what you're saying, I just don't understand why my code won't work for me. Quote Link to comment https://forums.phpfreaks.com/topic/261270-sessions-in-mail-function-failing/#findComment-1339793 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.