Solved

foreach

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Healthcheck 2 86
Hacked File Timestamps 4 50
Download a website to hdd 2 51
How can I change this hyperlinked phone number to be black and is it working? 2 21
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now