forumnz Posted December 21, 2007 Share Posted December 21, 2007 Hi, I am writing a script that send emails to up to 8 people, which uses emails provided by a user. I have 8 boxes named memail1, memail2 etc up to memail3. In the next page i have $memail1 = $_REQUEST['memail1'] ; right up to $memail8 = $_REQUEST['memail8'] ; I want to have a counter that counts how many have been submitted. How do I do that? Thanks, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/ Share on other sites More sharing options...
The Little Guy Posted December 21, 2007 Share Posted December 21, 2007 you could use just one textarea, and do this: Only one Email Per Line <?php $emails = explode("\n",$_POST['textarea']); $i = 0; foreach($emails as $email){ if(mail($subject,$to,$message,$headers)&&$i<{ $i++; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420745 Share on other sites More sharing options...
forumnz Posted December 21, 2007 Author Share Posted December 21, 2007 Thanks! This is what I have now: <?php $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $memail = $_REQUEST['memail'] ; $memail = explode("\n",$_POST['textarea']); $i = 0; foreach($memail as $email){ if(mail($subject,$to,$message)&&$i<{ $i++; } } echo $i; ?> Only problem is, it always displays 1, even if I enter 5 emails. Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420773 Share on other sites More sharing options...
emehrkay Posted December 21, 2007 Share Posted December 21, 2007 does it send multiple emails? if it does, the error is in your incrementing of $i Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420779 Share on other sites More sharing options...
forumnz Posted December 21, 2007 Author Share Posted December 21, 2007 For now, I just want it to count the emails. That does not work - any ideas? Thanks heaps! Sam. Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420786 Share on other sites More sharing options...
emehrkay Posted December 21, 2007 Share Posted December 21, 2007 echo count($memail); Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420790 Share on other sites More sharing options...
forumnz Posted December 21, 2007 Author Share Posted December 21, 2007 Still doesn't work. This is my form: <form action="email.php" method="post"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="12%">Name:</td> <td width="88%"><label> <input type="text" name="name" id="textfield" /> </label></td> </tr> <tr> <td>Email:</td> <td><label> <input type="text" name="email" id="textfield" /> </label></td> </tr> <tr> <td><p>Friends Emails:<br /> (separate with </p> </td> <td><label> <textarea name="memail" id="textarea" cols="45" rows="5"></textarea> <br /> <input type="submit" name="button" id="button" value="Submit" /> </label></td> </tr> </table></form> and my code: <?php $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $memail = $_REQUEST['memail'] ; $memail = explode("\n",$_POST['textarea']); $i = 0; foreach($memail as $email){ if(mail($subject,$to,$message)&&$i<{ $i++; } } echo count($memail); ?> Help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420797 Share on other sites More sharing options...
emehrkay Posted December 21, 2007 Share Posted December 21, 2007 try the place that echo before the mail function call. if you arent getting to the echo, there is something wrong with your mail call Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420798 Share on other sites More sharing options...
forumnz Posted December 21, 2007 Author Share Posted December 21, 2007 Not working. I dont get it. It shouldn't be that hard to calculate number of emails should it? Sam. Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420807 Share on other sites More sharing options...
forumnz Posted December 21, 2007 Author Share Posted December 21, 2007 Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420895 Share on other sites More sharing options...
The Little Guy Posted December 22, 2007 Share Posted December 22, 2007 if you are using my mail function, I am really sorry, I formatted the function wrong. <?php $emails = explode("\n",$_POST['textarea']); $i = 0; $subject = "hello!!"; foreach($emails as $email){ // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: ' . $email . "\r\n"; $headers .= 'From: My Site <[email protected]>' . "\r\n"; if(mail($email,$subject,$message,$headers)&&$i<{ $i++; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-420988 Share on other sites More sharing options...
Northern Flame Posted December 22, 2007 Share Posted December 22, 2007 you might want to add this to your if statement: mail($email,$subject,$message,$headers)&&$i<=8 since you can have a maximum of 8 emails Quote Link to comment https://forums.phpfreaks.com/topic/82726-number-of-emails/#findComment-421015 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.