I am looking for some guidance on using the phpMailer class.
I am currently calling the php mail() function in a loop to take input from a contact form on my website and send it to 60 email recipients - its is running like a dog and i realise i need something better. I believe doing this is calling starting the whole process with the mail server for every single email request. Will phpMailer improve this performance? How easy is it to implement? Cheers.
I use Swift Mailer, for my mailing needs which can be quite demanding, and never had a problem with it..
When I'm doing mailing I tend to run the script from a cron job so it doesn't impact the webpage, as with each itteration or mail sent you can't leave the page so you are in limbo, whereas running a php script from a cron job every hour or whatever period you need it gets you away from that issue. As long as you have your database setup well, maybe add a field with a "mailsent" type bool, int set it 1 or 0 as required, then it sends to the required recipients dependant on a small query...
Thanks Maeltar. A cron job is the way i want to go eventually but at present i dont think my hosting package has it. Therefore i wanted to do something to better process real time bulk mail sending. I am sure i read somewhere that if you use the standard php mail() function and loop it to send for example 50 emails it runs like a dog as its opening,processing then closing the mail protocol or something as opposed to just opening the protocal sending 60 emails then closing it again. Not particularly well explained but its clear looping on the php mail() function is causing some kind of processing issues around how the mail protocol works on the php installation. Needinhg a quick fix and i believe phpMailer will do that but looking on guidance re. how best to use.
mail() runs like a dog because, as you say, it will close the socket after each mail is sent, thus making it have to re-open again.
mail is good because its portable, but its not very good at sending multiple emails and also its very easy to fraff up the mail headers and cause your mail to be flagged as spam. also you must take into account your hosts send limit, and try to throttle the amount of emails sent by using sleep. Its all abit of a pain tbh.
SwiftMailer can do this properly, I haven't used PHPMailer so I can't say if it will or not.
First I think I should explain how mail() works across platforms.
If you are on a sane OS mail() uses sendmail (unless configured to use SMTP in the php config)
However if you are using a redmond operating system, for what ever reason (sane reasons for using windows so far have escaped my knowledge), mail() will be using SMTP anyway as sendmail doesn't exist on winblows, 'coz its bad :).
Swiftmailer provides tools for connecting to both SMTP and sendmail (which ends up being smtp anyway ... but I digress)
You will need to know either of the 2 following:
1. The path of the installed MTA binary of your server (sendmail, Postfix, Exim) if different from default: /usr/sbin/sendmail
2. SMTP server details
For this example I'm gonna use the sendmail method, using the default binary.
more info on sending mails and transport types: Send Docs
Plugins are by far the best reason to use Swift.
more information: Plugin Docs
Thanks sketchMedia this looks pretty straightforward and will easily into the class i have created for sending of all mails.
I aint got a clue about any of the set ups i have though. So i develop on my personal laptop with php and mysql installed on windows XP. I cant send emails anyway as there is no mail server.
On the hosted webspace environment i am sure it is something like CentOS or something. As i aint doing anything complicated havent really found any greate issue loading the php code developed and tested on Windows onto the Unix shared server environment. Any ideas how i would likely need to call Swiftmailer on the shared hosted enviorponment to make it work? Cheers.
CentOS is based on RHEL I think, so I'd wager your sendmail path is default: '/usr/sbin/sendmail', so you shouldnt need to specifiy a sendmail path and it should work fine.
As for your development env, why dont you set your gmail to be a smtp, so then you can test the functionality of the code before pushing it into the wild.
change the transport to be:
Google will most likly have a form of send limit, so you might wanna check before using it to send bulk messages.
|All times are GMT. The time now is 04:55 AM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0