passam Posted January 22, 2009 Share Posted January 22, 2009 I used a wizard to help myself with the code, modified variables and everything was ok until I added a check box. If I do check the check box everything work and I my email into my gmail account. But, if I leave it blank - that`s it. I get the error below. I moved it around changed lines nothing works. Help!? Please. Warning: Invalid argument supplied for foreach() in /home/content/a/c/r/mysite/html/sms.php on line 31 Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/c/r/mysite/html/sms.php:31) in /home/content/a/c/r/mysite/html/sms.php on line 94 My PHP <?php // ------------- CONFIGURABLE SECTION ------------------------ $mailto = 'into@mydomain.com' ; $subject = "Requesting Call Back AP:" ; $formurl = "http://www.mysite.com/index2.htm" ; $errorurl = "http://www.mysite.com/404.htm" ; $thankyouurl = "http://www.mysite.com/thankyou.htm" ; $email_is_required = 0; $name_is_required = 0; $uself = 0; $use_envsender = 0; $use_webmaster_email_for_from = 0; $use_utf8 = 1; // -------------------- END OF CONFIGURABLE SECTION --------------- $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ; if (!isset( $use_envsender )) { $use_envsender = 0 ; } $envsender = "-f$mailto" ; $name = $_POST['name'] ; $number = $_POST['number'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $time = $_POST['time'] ; foreach($_POST['check'] as $value) { //*****************this is line 31***********// $check_msg .= "$value\n"; } $http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (($email_is_required && (empty($email) || !ereg("@", $email))) || ($name_is_required && empty($name))) { header( "Location: $errorurl" ); exit ; } if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) { header( "Location: $errorurl" ); exit ; } if (empty($email)) { $email = $mailto ; } $fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ; if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } $messageproper = "\n" . "e-mail sent from: $http_referrer\n" . "\n" . "\n" . "\n" . "Contact Name: $name\n" . "Contact Number: $number\n" . "Contact e-Mail: $email\n" . "Requested Callback Time: $time\n" . "\n" . "$check_msg\n" . "\n" . "\n" . "Sender Comments:\n\n" . $comments . "\n\n .............( sender comments ended on this line )....................\n" ; $headers = "From: \"$name\" <$fromemail>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.13.0" . $headersep . 'MIME-Version: 1.0' . $headersep . $content_type ; if ($use_envsender) { mail($mailto, $subject, $messageproper, $headers, $envsender ); } else { mail($mailto, $subject, $messageproper, $headers ); } header( "Location: $thankyouurl" ); //******* << this is line 94*******************// exit ; ?> My form: <form name="form" id="form" class="form" action="sms.php" onSubmit="return validate(this)" method="post"> <table class="block-header" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr valign="bottom"><td width="25%"><br></td><td width="75%"><h1>Text Text</h1></td></tr></tbody></table> <table class="content" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody> <tr valign="top"> <td width="8%"><div style="width: 40px;"><br></div></td> <td class="label" width="17%">Contact`s Name:</td> <td class="input" width="50%"> <!-- <input name="timestamp" type="hidden"> --> <input name="name" type="text" value="" style="width: 35%;" id="name"> </td> <td width="25%"><br> </td> </tr> <tr valign="top"> <td width="8%"><div style="width: 40px;"><br></div></td> <td class="label" width="17%">Contact`s Number:</td> <td class="input" width="50%"> <input name="number" type="text" value="" style="width: 35%;" id="number"> <span class="commentSmall"> Please include #extentions </span><br> </td> <td width="25%"><br></td> </tr> <tr valign="top"> <td width="8%"><div style="width: 40px;"><br></div></td> <td class="label" width="17%">Email Address:</td> <td class="input" width="50%"> <input name="email" type="text" value="" style="width: 35%;" id="email"> <span class="commentSmall"> We respect your privacy </span><br> </td> <td width="25%"><br></td> </tr> <tr valign="top"> <td width="8%"><div style="width: 40px;"><br></div></td> <td class="label" width="17%">What can we do for you?</td> <td class="input" width="50%"> <textarea name="comments" class="input" value="" rows="5" cols="35" style="width: 60%;" id="comments"></textarea> <span></span><br></td> <td width="25%"><br></td> </tr> <tr valign="top"> <td width="8%"> <div style="width: 40px;"><br></div></td> <td class="label" width="17%">text text</td> <td class="input" width="50%"> <input name="time" type="text" value="" style="width: 60%;" id="time"> <br><span class="commentSmall"> text </span><span class="comment"> tetxt </span><br> </td> <td width="25%"><br></td> </tr> <tr valign="top"> <td colspan="2"></td> <td class="input" width="50%" nowrap="nowrap"> ******************************************************************* <input name="check[]" type="checkbox" value="I am requesting a callback for someone esle" > –– check please if requesting a callback for someone esle</td> ******************************************************************** </tr> <tr><td colspan="2"><br></td> <td colspan="2" id="pinfo" class="label"> </td> </tr> <tr valign="top"> <td width="8%"><div style="width: 40px;"><br></div></td> <td width="17%"><br></td> <td width="50%"> <input type="submit" value="Submit" > <input type="reset" value="Reset" > </td> <td width="25%"><br></td> </tr> <tr> <td colspan="4"><br></td> </tr> <tr valign="top"> <td colspan="2"><br></td> <td class="body"> <p> <a href="http://">text</a>, tetxt.</p> </td> <td><br></td> </tr> </tbody></table> </form> Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 22, 2009 Share Posted January 22, 2009 Warning: Invalid argument supplied for foreach() in /home/content/a/c/r/mysite/html/sms.php on line 31 this warning is what sends your headers.. then you get the error seen below which is headers already sent.. and as for line 31 $_POST['check'] is not an array.. try <?php print_r($_POST); ?> and see what it has for 'check' Quote Link to comment Share on other sites More sharing options...
landavia Posted January 22, 2009 Share Posted January 22, 2009 for check. u should use simple value btw.. in the post result there are't any check but is found $_POST['check[]'] ^^ Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 22, 2009 Share Posted January 22, 2009 landavia name="check[]" is supported by php it will form an array inside of $_POST['check'] so his code is correct, it is just not grabbing anything.. OOOH also if the checkbox isn't checked, it won't show up in your POST.. which could explain the error, you could hide warnings.. or output buffer ob_start Quote Link to comment Share on other sites More sharing options...
landavia Posted January 22, 2009 Share Posted January 22, 2009 sry.. i missed that well.. to avoid error.. u should try trap them with if($_POST['check']){ foreach($_POST['check'] as $value) { //*****************this is line 31***********// $check_msg .= "$value\n"; } } Quote Link to comment Share on other sites More sharing options...
passam Posted January 23, 2009 Author Share Posted January 23, 2009 RussellReal thank your for your help. And Landavia thank you for yours. I just went with trapping I was not sure how to use ob_start(). The trapping works in both cases: with checked box and empty. Again Thank you so much to Both of you for your HELP!!! I just used the code Landavia left: if($_POST['check']){ foreach($_POST['check'] as $value) { $check_msg .= "$value\n"; } Quote Link to comment 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.