I am send email using php mail function.But it takes long time to receive to the user.It should receive with 10 minutes.how can i do that and why it is taking long time to receive more than 30 minutes its taking now.
it might be that the recipient is not the one to blame, sometimes it is due to the ISP. In our country, our ISP provider accepts lots of requests that the queue may pile up. This is when using the ISP provided SMTP server as a SMTP relay server.
Also the PHP mail() function has a limit depending on you host or server (first a volume limit and then a limit preventing you to send X emails in a row).
Were I you, I would use third parties APIs, like SendGrid or MailChimp... (they also provide mail tracking, error reports, opting out...) and are quite easy to use.
Related
I am done with my set up . mail sending is also working properly but taking to much time to send the mail.
Plz tell me way by which i can fix this issue .
Use queues https://laravel.com/docs/5.6/queues
The mail will be added to queue and sent later. Does not need client to wait for request to finish.
Unless you run multiple workers in parallel. If your SMTP server's connection takes a second, you'll send 10 emails per second if you have 10 workers. But check with your IT to see if they aren't throttling by IP addresses.
But honestly, either your IT looks at why their SMTP server can't send emails fast enough, or you look at using an external server to do your mass mailing.
So i suggest you that please change your SMTP Server. It may be help you.
For more information :
https://www.reddit.com/r/laravel/comments/6e7knm/mail_facade_very_slow_sending_email_with_local/
https://learninglaravel.net/learn-to-send-emails-using-gmail-and-sendgrid-in-laravel-5
We have an internal message board. If a user posts a note then all other users that have access to the thread are sent an email alert. So if there are 20 users on a thread then you could see bursts of 100s of emails over only a couple minutes.
Currently the email alerts are sent with the PHP mail() function. One time we got some local relay alerts and I think our server IP was blacklisted for a short period of time. And I think these negative consequences happened because of an email alert burst that uses mail().
Is the solution simply to use anything other than mail(), or is there more to it? How can I reproduce/test the local relays and blacklisting so that I am sure the issue is solved?
If you're sending large amounts of email the best thing you can do is use a third party email provider. There are several that offer API/SMTP services and will not be blacklisted because they work on a reputation system. Most offer composer packages you can drop in and configure relatively quickly.
SendGrid / sendgrid-api - We use this to send around 2 million emails a month without issue.
Mailgun / mailgun-php
Mandrill / mandrill-api-php
Each have their pros and cons and some offer free emails to a certain limit.
If this isn't an option you should create a dedicated email server that has all the correct DKIM/SPF records that over time will become reputable over time however it'll still slow down when you're sending many emails as it'll be limited to 1 email at a time and if it encounters a slow connection it can take a while to complete. If email is important a third party provider is definitely the best way to go.
I have an issue. I have situation where I need to send around 3000 emails per request using SMTP. However, only 30-40 reaches destination.
Do you have any idea what can be a problem and how to solve it. as server side script I am using PHP.
How the big e-mail service providers (Constant Contact, WhatCounts, etc.) do mass e-mails is to put the "campaign" in a queue and send it at a later time. They have dedicated, high-performance delivery software for looking through the queue for new campaigns to send and then send them out at rates exceeding 50,000 messages per minute. Anything you might do in PHP won't even compare.
If you are trying to send from your local computer, that won't work. DNSRBL lookups will identify your computer as being on a "DUN" (Dial-Up Network) and will block the message. Most PHP scripts also have a timeout of 30 seconds in a web server environment but running via cron a PHP script can run as long as it needs to.
You shouldn't send mass e-mails from your main e-mail server either. That's a nice, fast way to get on global blacklists so that you can't send regular e-mail to common hosts (e.g. Hotmail, GMail, etc). The big e-mail service providers have dedicated staff whose job it is to remove themselves from global blacklists. That's a full time job. You are better off paying for the service (don't forget to set up SPF records correctly if you do go this route).
Warnings and advice aside, to answer the question, use a cron job for your PHP script and put the e-mails to be sent out in a queue.
If your looking to inboxing as many emails as possible and you are not sending spam, and prefer to use your own smtp, check them out.
I have over 4,000 users who subscribed to weekly updates via email. To send an email, I simply use:
mail($to,$subject,$message,$headers);
Which works perfectly fine. My question is: how many emails can you send at once? Can I send all 4,000 at once by stepping through array of emails inside a loop? Or will that cause a time-out situation, wjere only part of the list receives emails?
Generally, your limit is PHP's memory allocation and script timeout, both of which can be increased. A bigger limiting factor is spam firewalls, which typically limit the number of emails that can come from a server and to another domain. Bulk email services use intervals to limit the amount of mail sent to any given domain during a given time period.
PHP has no limit, and you can do what you say and run it in a tight loop.
On linux it is sendmail, or a sendmail clone. If it starts to get overloaded it should start queueing your mails, and delivering them when it can. For Windows you have a socket connection, and I suppose the mail server might start refusing connections if it got overloaded.
Unless you are in a hurry to send them all, consider a sleep(2) between each call to mail(). If all goes smoothly then try sleep(1) the next time. Then usleep(500000) next time, etc. (UPDATE: following Matt's suggestion, put set_time_limit(10) inside the loop to avoid running out of CPU time.)
If you want them sent out even quicker you round-robin with multiple local relays. (On windows you could handle this by setting the SMTP php.ini setting; on linux you'd use on of the libraries that sends email over a socket.) Or consider a professional mail broadcasting service, where they take care of all these issues for you.
EDIT Just saw your comment about running it from your Mac. I'd assumed a server situation, with a real mail server with a global IP. If your Mac is behind a firewall you are most likely set to forward all your email to your ISPs mail server. Your ISP may well get upset about receiving 4000 emails from you in a short period of time. (E.g. they may assume your machine has been compromised by a virus and shut you down.)
Also, on shared hosting, agreeing not to send out lots of email is often part of the contract. So be careful there too.
It does not depend on php, but it depends on your sendmail server capability and your hosting provider support on the limit of emails that you can send with in a span of time..! PHP only puts your email in the sendmail queue...!
Considering that loop will be sequential you can send them all at once by looping. It's more mailserver dependent, rather than PHP.
Although if you're using WAMP, that might cause a problem, because behavior of mail() under windows is different. Instead of talking to an MTA it tries to use sockets to deliver mail.
Giving exact numbers is not possible.Its depends on your mail server & maximum execution time.
Best practice to send large number of email is "cron job"
I'm improving PHP mailing list code that uses mail() in a loop while iterating through all subscribers. The script used to display a "Maximum execution time of 30 seconds exceeded" error which I solved by adding set_time_limit(0);.
Now there's no error but it took about seven minutes to send 100 messages. What are my options?
Will sending just a single message with all subscribers in BCC help or is it the same "behind the scenes"?
Sending to all as BCC will be a lot faster. The code will execute faster and mail() will be executed only once.
This is the quick fix, but as mentioned, a large BCC list is a safe road to the spam folder. However, using mail() is a sure destination to spam too.
If you want to actually improve it, use PHPMailer from SourceForge and send via SMTP (less spam hits) using cron in batches of X emails once.
The PHP docs state:
Note:
It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.
For sending large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.
Sending to all subscribers by specifying them in BCC shouold work faster. Though, while it might be a good option for some private environment, I would not suggest to do that in public web pages/systems, as many might consider such email being a spam.
One option would be to send emails via cron job. In that case, it doesn't really matter how much time it takes to send an email, as long as all emails are eventually sent.
Since you're simply asking for options, here are a few:
Profile your code, and see why its slow. Maybe you could iron out a few efficiency issues.
Relying on the mail() function is usually not advisable, especially since better alternatives like swiftmail or Zend_mail exist. Although these might be overkill for small mailing requirements
It could, possibly, be a server related issue? Maybe talk to your server administrator.
Cron Job is better idea. I used this and it works...
Profile you code will help you to figure out the problem.
I do recommend sending the mail via BCC because it will be a lot faster. Your script just has to make one connection to the SMTP server and this server will do the rest for you.
I would also take a look at for example PHPMailer or PEAR::Mail.
The bad thing about the mail() method for bulk mails is that it will open a new socket to a SMTP server for every email thats send.
A good mail library will create a socket connection to the SMTP server once and will then send all the emails and closes it at the end.
To speed it up a bit more you could also look at your SMTP server configuration (if possible) and try to increase the daemons etc.
You might also want to take in consideration that some SMTP servers have maximums you can send.