Mail to a list of people

Reply

Join Date: Nov 2006
Posts: 37
Reputation: Firestone is an unknown quantity at this point 
Solved Threads: 0
Firestone Firestone is offline Offline
Light Poster

Mail to a list of people

 
0
  #1
Aug 18th, 2007
I'm trying to mail a newsletter to a list of people, but I get an error every time it tries to mail. Anyone know what I'm doing wrong?

  1. <?php
  2. $file = fopen("upload/newletter.html", "r");
  3. $sub = fopen("to.txt", "r");
  4. $x = 0;
  5. $y = 0;
  6. while (!feof($sub))
  7. {
  8. $names[$x] = fgets($sub);
  9. $x++;
  10. $y++;
  11. }
  12. while (!feof($file))
  13. $content = $content . fgets($file);
  14.  
  15. echo $content;
  16. $x = 1;
  17. while ($x <= $y)
  18. {
  19. mail($names[$x], "Branches and Roots Weekly Newsletter", "Testing");
  20. $x++;
  21. }
  22. ?>

Heres the error I get:
Warning: mail(): Bad parameters to mail() function, mail not sent. in (Directory) on line 19
=================================
There are 10 types of people in the world,
Those who understand binary, and those who don't
=================================
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 223
Reputation: Anonymusius is on a distinguished road 
Solved Threads: 10
Anonymusius's Avatar
Anonymusius Anonymusius is offline Offline
Posting Whiz in Training

Re: Mail to a list of people

 
0
  #2
Aug 19th, 2007
I don't see any problems in my first glance, try to put a print_r($names); somewhere and see whether the array contains email adresses valid for PHP to swallow ( http://nl3.php.net/manual/en/function.mail.php ).

BTW, $x = 1;, shouldn't that be $x = 0;? Or does the file your loading first have an empty line or something like it?

You might to want to check your php.ini is fully configured for sending mail: http://nl3.php.net/manual/en/ref.mail.php .
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 750
Reputation: pritaeas is on a distinguished road 
Solved Threads: 122
Sponsor
pritaeas's Avatar
pritaeas pritaeas is online now Online
Master Poster

Re: Mail to a list of people

 
0
  #3
Aug 20th, 2007
You can simplify your file handling by using file_get_contents() followed by an explode(), should the problem lie in invalid email address.

http://nl3.php.net/manual/en/functio...t-contents.php
http://nl3.php.net/explode
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 37
Reputation: Firestone is an unknown quantity at this point 
Solved Threads: 0
Firestone Firestone is offline Offline
Light Poster

Re: Mail to a list of people

 
0
  #4
Aug 20th, 2007
There are no invalid e-mails, and I found that if I hard code it, it will work. However I can't hard code it for what I'm trying to do, so anyway I can fix it?
=================================
There are 10 types of people in the world,
Those who understand binary, and those who don't
=================================
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,351
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 500
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Mail to a list of people

 
0
  #5
Aug 20th, 2007
As Anon said above, drop in a print_r or var_dump of $names to see what you have there.
Also,
  1. foreach ($names as $to) {
  2. mail($to, "Branches and Roots Weekly Newsletter", "Testing");
  3. }
would make your loop a bit easier.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 61
Reputation: Eko is an unknown quantity at this point 
Solved Threads: 1
Eko's Avatar
Eko Eko is offline Offline
Junior Poster in Training

Re: Mail to a list of people

 
0
  #6
Aug 22nd, 2007
Originally Posted by Firestone View Post
I'm trying to mail a newsletter to a list of people, but I get an error every time it tries to mail. Anyone know what I'm doing wrong?

  1. <?php
  2. $file = fopen("upload/newletter.html", "r");
  3. $sub = fopen("to.txt", "r");
  4. $x = 0;
  5. $y = 0;
  6. while (!feof($sub))
  7. {
  8. $names[$x] = fgets($sub);
  9. $x++;
  10. $y++;
  11. }
  12. while (!feof($file))
  13. $content = $content . fgets($file);
  14.  
  15. echo $content;
  16. $x = 1;
  17. while ($x <= $y)
  18. {
  19. mail($names[$x], "Branches and Roots Weekly Newsletter", "Testing");
  20. $x++;
  21. }
  22. ?>

Heres the error I get:
Warning: mail(): Bad parameters to mail() function, mail not sent. in (Directory) on line 19
Some advice :
1.Always test if the file exists , first :
  1. if(!file_exists("to.txt"))
  2. die("File could not be found");
2.
  1. $names[$x] = fgets($sub);
  2. $x++;
I assume you are familiar with C , but in php it's easier to do this:
  1. $names[]=fgets($sub);
It will start from 0 and get on the next element at every loop.
And later if you wanna know the number of elements in the array,you can use count($names);

3.With strings you can also use a very used shortcut, so instead of:
  1. $content = $content . fgets($file);
you cand just as easily write :
  1. $content.=fgets($file);
which does the same thing

Anyway,back to our sheeps , the $names[] array is the problem.
As the others said,try to print it out , see if you have the correct info.
Oh,and btw,I hope you are running the script from a server that supports the mail() function( not the localhost)
Last edited by Eko; Aug 22nd, 2007 at 5:07 pm.
"Get rich or die tryin"(50-cent)
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 19
Reputation: nyashaC is an unknown quantity at this point 
Solved Threads: 0
nyashaC nyashaC is offline Offline
Newbie Poster

Re: Mail to a list of people

 
0
  #7
Aug 25th, 2007
$x = 1;

Change this
to

$x = 0;

There is no records at $names[0] which is where the while loop is starting
NyashaC
"My logic is undeniable"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC