PHP timed script execution - php

I am not quite sure how to put my question into words, but this is what I am trying to build. I want to send email using PHPMailer through my gmail account. Now, Gmail has a limit of 500 emails in one day. Another thing to consider is, when you send a bulk email at once, there is a chance that my email is sent back to me, as my bulk email is considered to be a spam. I have around 200 in my contact list. So a limit of 500 is not a problem. Now my question is, is there any native PHP function that will only execute the send function of PHPMailer in a certain amount of time duration? What I want to do is, I want to send 10 emails from my contact list every 30mins.. So if I have 200 in my contact list, there is an interval of 30 mins in every 10 contacts until I send the email to everyone. I have no problems creating the email script using PHPMailer. I just need to know if there is a way in PHP to 'time' the execution of my functions. I would appreciate any kinds of help. Thank you!

I think you should really look for third party solutions. Sending bulk emails via Gmail or any other provider will create problems for you.
I am using MailGun (with 200 mails you can use FREE version) for years and it does the job.
Don't forget to check mailgun for PHP.

Related

Sending emails using php. whithout framework

I need help, I have a question.
currently, I'm working on a website using PHP.
this website needs to be able of sending verification emails. I used the PHP mail function to send emails by using my personal email as the sender, but it takes a long time to be sent.
my question is if the user of this website gonna uses a professional email, for example buying one from GoDaddy.
is this gonna make the process of sending emails faster.
in other words, I want to know if the emails take so long to be sent because of my code, I mean is there is another way to send an email using PHP other than the mail function?
or it depends on the email used to send the email.

how to call php page to work in background?

I am working on an email system , All things go fine , I can send email without any error, I have more than 3000 email address and I want to send email to them , but when I press on send button the operation took more than one hour , so I decided to use pear queue mail package, the package now insert the emails queue inside database, but how can I run send function after inserting it in database in background so user will not get confused from a long time that he had to wait .
using loop is a long process to send email one by one it is better to send bulk email. SwiftMailer is best to do that.
use SwiftMailer, which has HTML support, support for different mime types and SMTP authentication (there are very low chances that your email will go into spam).
also, I would like to tell you when you run a long process in PHP it gets time out after some time. you have to increase the execution time in php.ini file.
if you want to stuck with your process(loop).

Best way to loop smtpmailer email php loop

I run a website where I would like to start sending out an email newsletter to the registered users that opted in. Currently, there are about 700 users. I use a gmail account with smtpmailer to currently send all my notifications and it works well. However, when I ran my loop script to send out the personalized newsletter, the webpage with the loop eventually errors out after getting through maybe 100 users.
I didn't think this was really that heavy of a load. Should I be following a better practice for this?
My code process is essentially as follows
Connect to server
set_time_limit(0);
While loop for all users who are subscribed
Build custom message
Send Email
End Loop
Thanks
This is not what your Gmail account is for. Gmail intentionally puts blocks in place to prevent this or at least de-rail your attempts.
There are many free for small account SMTP providers out there with various restrictions.
http://www.SendGrid.com Send up to 400 emails a day (12,000 emails a month)
http://www.MailChimp.com Send 12,000 emails a month to a list of up to 2,000 subscribers
Those are two of the big ones but there are plenty of smaller outfits as well.
Gmail allows you to send only 50 mails per hour.

Sending large number of emails with attachments in Cakephp

I am using CakeEmail to sent about 7000 emails in a loop. But when I sent emails with small attachments of about (1kb) its working fine. But when I use bigger attcahment files such as of size 800kb it just quite after sending some emails may be 23 or 60. But not completing the process.
The Page quits by giving a message "This webpage is not available"
The code is in a loop where each CakeEmail is initialized to sent to an email address
I tried using
set_time_limit(0);
But it didnt work.
Can anyone helps me out why its not able send using an attachment of 800kb ?
Some shared servers do not allow to run longer scripts, thus not allowing to override the time limit.
Might be you can do something to send 10 emails at a time and then redirect the browser to the same page to send another 10. Just fetch the specific 10 emails using DB LIMIT clause.
Or you can also create a cron job to run the script through shell.
PS - kindly provide the code you are using so I can help in modifying it

How to Ensure Instant Email Sending Through PHP

I have made a Registration Page for the Users to get registered and When User Will be registered a confirmation Email will be sent to the User Email Address. But The PHP mail() function some times sends email instantly and some times after several minutes and The Mail also goes to the SPAM Box. I have seen so many forums where Mail is sent instantly and does not go to SPAM Box and goes directly to Inbox.
How can I solve my above mentioned Problems.
You can't speed up the process of sending mail with just PHP. As for the spam issue, this is one of many issues with the PHP mail() function. You can take a look at the headers of the emails that are being marked as spam and usually it should give some kind of indication as to why it's spam. Also, check the headers in the email you're sending. As I said, the mail() function can be tough to work with. Go with a better solution:
PHP Mailer or Swift Mailer
Regarding your lag: you could save the message in a database and use a cron every minute to send the mails which are in the queue. The user will usually get the message within 1 minute.
Regarding your SPAM problem: use a SaaS like http://www.sendgrid.com
Mailchimp would be better for this : http://mailchimp.com/

Categories