| | |
Mail to a list of people
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2006
Posts: 37
Reputation:
Solved Threads: 0
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?
Heres the error I get:
Warning: mail(): Bad parameters to mail() function, mail not sent. in (Directory) on line 19
php Syntax (Toggle Plain Text)
<?php $file = fopen("upload/newletter.html", "r"); $sub = fopen("to.txt", "r"); $x = 0; $y = 0; while (!feof($sub)) { $names[$x] = fgets($sub); $x++; $y++; } while (!feof($file)) $content = $content . fgets($file); echo $content; $x = 1; while ($x <= $y) { mail($names[$x], "Branches and Roots Weekly Newsletter", "Testing"); $x++; } ?>
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
=================================
There are 10 types of people in the world,
Those who understand binary, and those who don't
=================================
I don't see any problems in my first glance, try to put a
BTW,
You might to want to check your php.ini is fully configured for sending mail: http://nl3.php.net/manual/en/ref.mail.php .
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 .
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
http://nl3.php.net/manual/en/functio...t-contents.php
http://nl3.php.net/explode
•
•
Join Date: Nov 2006
Posts: 37
Reputation:
Solved Threads: 0
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
=================================
There are 10 types of people in the world,
Those who understand binary, and those who don't
=================================
As Anon said above, drop in a print_r or var_dump of $names to see what you have there.
Also, would make your loop a bit easier.
Also,
PHP Syntax (Toggle Plain Text)
foreach ($names as $to) { mail($to, "Branches and Roots Weekly Newsletter", "Testing"); }
•
•
•
•
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?
php Syntax (Toggle Plain Text)
<?php $file = fopen("upload/newletter.html", "r"); $sub = fopen("to.txt", "r"); $x = 0; $y = 0; while (!feof($sub)) { $names[$x] = fgets($sub); $x++; $y++; } while (!feof($file)) $content = $content . fgets($file); echo $content; $x = 1; while ($x <= $y) { mail($names[$x], "Branches and Roots Weekly Newsletter", "Testing"); $x++; } ?>
Heres the error I get:
Warning: mail(): Bad parameters to mail() function, mail not sent. in (Directory) on line 19
1.Always test if the file exists , first :
PHP Syntax (Toggle Plain Text)
if(!file_exists("to.txt")) die("File could not be found");
PHP Syntax (Toggle Plain Text)
$names[$x] = fgets($sub); $x++;
PHP Syntax (Toggle Plain Text)
$names[]=fgets($sub);
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:
PHP Syntax (Toggle Plain Text)
$content = $content . fgets($file);
PHP Syntax (Toggle Plain Text)
$content.=fgets($file);
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)
![]() |
Similar Threads
- I love this spam! (Geeks' Lounge)
- Lous Notes 6.5 Mail Group Issue (Windows NT / 2000 / XP)
- how to create mailing list (MySQL)
- Advertising Your Site for Free (Promotion and Marketing Plans)
- how to hide email recipient list (PHP)
Other Threads in the PHP Forum
- Previous Thread: MySQL datatype problem....
- Next Thread: updating database problem
| Thread Tools | Search this Thread |
301 advanced apache api array autosuggest basics beginner broken cakephp class cms code combobox compression cron curl data database date datepart display dropdownlist dynamic email eregi error execution file files folder form forms function functions google head href htaccess html httppost if...loop image include includingmysecondfileinthechain ip javascript job joomla jquery js key library limit link login md5 menu mlm multiple mysql mysql_real_escape_string oop password paypal pdf pdfdownload php phpvotingscript problem procedure query random screen script search searchbox server session sessions smarty source space sql stored system table traffic tutorial unicode upload url variable video volume votedown web website youtube zend






