Solved

foreach

Posted on 2004-04-12
4
442 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
  • 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

831 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