Solved

foreach

Posted on 2004-04-12
4
445 Views
Last Modified: 2008-03-06
um, this is my first attempt at using 'foreach', I must have something wrong:

I have a txt file that is a list of email addresses, one per line.

The script below sends to the first name on the list, then says 'done'.  Doesn't send to the remaining addresses.  Do you see what's wrong?    Also... would it be reasonable to use this script for 4000 emails, or is it likely to overwhelm my server (p4, 512 ram, light load)?

Thanks,     Chris

<?
$emaillist_url = 'list.txt';

$content = file_get_contents($emaillist_url);

$emailarray = explode("\n",$content);

foreach ($emailarray as $email)  {

mail("$email","update - Test Mail!","

Hi,

Just testing the email script

","From:updates@mysite.com");

}

PRINT 'done';
?>
0
Comment
Question by:ChrisAndrews
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
jkna_gunn earned 50 total points
ID: 10811355
<?php
$contents = file('list.txt');
foreach($contents as $email) {
   mail($email,"update - Test Mail!","hi etc","From:updates@mysite.com");
}

print "done";
?>

0
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10811364
if there are problems you might have to use rtrim() on the $email variable before using it in the mail function

$email = rtrim($email);
0
 

Author Comment

by:ChrisAndrews
ID: 10813429

Thank you :)

It seems to loop back and resend the very first email, but I can work around that (use my own address),

Chris
0
 

Author Comment

by:ChrisAndrews
ID: 10813731

oh, I think the rtrim fixed that, will test again,

Chris
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question