papaface Posted June 7, 2007 Share Posted June 7, 2007 Hello, I have the following code: <?php $filename = "email_send.txt"; $lines = file($filename); foreach($lines as $line_num => $line) { if (ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$line)) { //mail('$line', 'ORDER', $msg, "Content-Type: text/html\nFrom: [email protected]"); echo $line; } } ?> When i run this, it only prints one email address out when there are three valid emails in the text file. i have found that it is because if the if statement that this occurring, how do I get around this problem. I want something to happen to the email address on each line of the text file IF the email is valid using the regex Link to comment https://forums.phpfreaks.com/topic/54655-solved-if-inside-foreach/ Share on other sites More sharing options...
papaface Posted June 7, 2007 Author Share Posted June 7, 2007 Can anyone help me on this? It would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/54655-solved-if-inside-foreach/#findComment-270317 Share on other sites More sharing options...
papaface Posted June 7, 2007 Author Share Posted June 7, 2007 Please? Link to comment https://forums.phpfreaks.com/topic/54655-solved-if-inside-foreach/#findComment-270341 Share on other sites More sharing options...
Psycho Posted June 7, 2007 Share Posted June 7, 2007 A little impatient aren't you? I see nothing wrong. Can you provide an example of how the data is formatted in the file and some of the emails that are not being being validated. Link to comment https://forums.phpfreaks.com/topic/54655-solved-if-inside-foreach/#findComment-270346 Share on other sites More sharing options...
papaface Posted June 7, 2007 Author Share Posted June 7, 2007 Yeah, this is for someone. It has worked for me in the past but I cant for the life of me work out what is wrong. The text file is formatted: [email protected] [email protected] [email protected] Only the last in the list gets displayed. Link to comment https://forums.phpfreaks.com/topic/54655-solved-if-inside-foreach/#findComment-270348 Share on other sites More sharing options...
papaface Posted June 7, 2007 Author Share Posted June 7, 2007 fixed <?php $filename = "emails.txt"; $lines = file($filename); foreach($lines as $line) { $line = rtrim($line); if (ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$line)) { //mail($line, 'ORDER', test, "Content-Type: text/html\nFrom: [email protected]"); echo $line ."<Br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/54655-solved-if-inside-foreach/#findComment-270357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.