![]() |
PHP: How to send mail in a foreach loop?
Here's my code:
PHP Code:
|
there are some problems with that code in general, but you should add some error handling to help with debugging.
Personally I would dump pear mail and use swiftmailer library. Just a suggestion to make things a little easier for you. They also have some plugins that you might find helpful swiftmailer.org |
Super fast.
|
Quote:
If you'd like I can create a custom script for you, or fix this one for $65/hr. Just hit me up. Contact info in signature. |
like someone said earlier try mail() 10x easier to get working, if it still doesn't work, icq: 33375924 and I'll work out what the problem is for a few bucks...
|
Paste your connect.php, I bet the problem is there.
Just BCC it to me so that Josh doesn't see it. |
do not implode a list and BCC it all, that will have a number of negative effects on deliverability.
I would agree with using mail() function instead of a library, unless you are sending tens of thousands of mails. Your MTA will most likely be a bigger bottleneck then php's mail() function. you really shouldnt need much error handling on such a simple script. i think your code could be cut to half as many lines though. |
If it's best not to loop and mail or implode a list and BCC it all, what is the best way of doing this?
I know my code is newbie as I'm new to the php coding scene (bought a decent book last year) and how the code could be cut in half but I plan on redoing it as I learn more. This is for a small non-profit site to help me learn the language. Thanks for everyone's input so far. |
Overall without any debugging at all you will not know the exact problem - it could be a number of things.
Using mail may not be simpler if the code problems lie in the database perhaps wrong formatted to address, etc. So your mail code could be fine, but because of something else it isn't working, so changing to mail would make no difference. I don't think there's anything wrong with using pear in your case, I personally dislike it but its just a matter of preference. Also you want to send mail in batch but the problem with using mail function is that its inefficient in a loop, pear is actually more appropriate usage. Granted you may not have 100k users, but that isn't the point. I recommended that library because it will simplify things for you and also be efficient. The docs might also help explain things better for you to give you a better understanding in general. Again, I personally dislike pear. It's just a matter of preference Also if you wanted to add attachments or something it would be a pain in your ass using mail function. Also your code has efficiency issues and also security issues. You should also try to read about prepared statements Either way don't let people on a board tell you workarounds or cutting corners for things especially if you don't know better and are just learning. If you know why you are cutting corners then it's fine, but if you do it just blindly then you will never learn "proper" |
does database even return any results? also use switftmailer or something like that.
this is definitely a spaghetti code,pretty ugly |
All times are GMT -7. The time now is 08:39 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123