Logics between php mail(), sendmail(), using SMTP in php - php

what is the main Logics between php mail(), sendmail(), using SMTP in php
why we are creating noreply1#domain.com, noreply2#domain.com,... and so on. Is there any problem in this?
WE are building Newsletter management which we try to sent minimum 6000 mails per day. Our domain is in dedicated sever.
We are trying to sent 10,000 mails per day.
Which is the best solution.
I tried out swiftmailer it sent 4 mails and stoped with error message
"Unable to send message due to connection error"
some time it sent 100 and stopped.
What may be the problem is? Is it a coding problem or server problem

I think your first action should be to check the SMTP server you're using (I assume you are using SMTP) whether it has any sending limits imposed. Then, speak to your ISP / provider whether they have any kind of spam detection in place that could prevent the sending of mass E-Mail.
If you are not using SMTP, but mail(), switch to SMTP. Mail() opens a new connection for every outgoing mail and is not recommended for sending larger quantities.
If nothing else helps, split the E-Mails into smaller jobs, making them easier for the server to digest, and/or add a few hundred milliseconds' pause in between sending of each mail.

mail() does not use SMTP; it delegates the actual sending of mail to the sendmail binary, so you have to configure the MTA on your system properly in order for it to work.

There is no sendmail() function in PHP.
I tried out swiftmailer it sent 4 mails and stoped with error message
"Unable to send message due to connection error"
Probably not a code error. Most likely candidate is that the SMTP server you are using is throttled to prevent use for bulk email sending. Have you asked your server provider / SMTP admin guy?
Solution is to run your SMTP server.
C.

Related

how many mail can be send from php mail() function?

i m working on job portal, for job alert i am sending mail for each user as per his/her subscription using cron job of php script. i have more than 10000 users(jobseekers) in portal. does php native function mail() can send more than 10000 mail without using smtp or other mail server?
and sorry for bad English.
can send more than 10000 mail without using smtp or other mail server?
No it cannot send even 1 email if you don't provide it either of them. If you don't provide an external smtp then you have to have a mail server installed on the machine itself. Once that is done, 10k mails are not a problem.
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 the sending of large amounts of email, see the » PEAR::Mail, and »
PEAR::Mail_Queue packages.
Reference:

MTA for receiving mails, in PHP

is there a library/class/code-snippet/etc. that allows me to directly receive mail in php?
So that I don't have to run an additional sever in an other process and then have to somehow send the mails to the already-running php-process.
I've been looking around for a while, but results for "php" and "mail" or "mta"/"smtp" on google focus mostly on sending mail, or retrieving it using pop3 or imap...
[EDIT]
What I'm trying to do is forward the messages to an IRC-channel, so obviously when the IRC-bot (in PHP) isn't running, loosing the mails is not a big deal. However having a low latency between receiving the mail and posting it on IRC is.
I've never seen a compete SMTP server in PHP and it doesn't surprise me. I don't think you want to go that route. I can think of two other ways to do this:
Use procmail (or similar) with your existing SMTP server and make a rule that forwards the messages to your PHP script. Pretty simple to do and it will fire the script the instant the message is received.
Have the messages delivered to some existing mailbox, then have your PHP script continually poll it (via POP or IMAP) for new messages. When you see a new message, pass it to IRC and delete it. How long it takes the message to appear depends on how often you poll the inbox.
Writing your own SMTP server to act as a MTA is a big undertaking. You could take a look at http://cloudmailin.com. CloudMailin allows you to receive the incoming email as an HTTP Post and acts as the MTA sending the email direct to your PHP app. The PHP app can then process the email and send it to the IRC channel.
The MTA (Mail Transport Agent) is an application (i.e. sendmail, exim) that is used to move mail from location to location. As far as I know, there is no MTA coded in PHP. PHP offers classes and scripting that will handle mail transport, but it still processes through an existing MTA.
You should be able to configure the MTA to pass mail through a given PHP script to accomplish what you are looking for.
Writing your own SMTP server is a huge undertaking. Do NOT go this route. You'll waste an incredible amount of time duplicating work that's been done already. Choose one of the 'big' SMTP servers (postfix, exim, sendmail, etc...) and go with that.
Don't think that just setting up a dinky little script to listen to port 25 will do the trick. SMTP servers are incredibly complicated beasts and the mechanics of setting up that port 25 socket likely occupy less than 0.00000000000000000000000000000000001% of the work. (this number is totally true, I asked my gut what it feels and that's what came out).
Try this: http://www.php.net/manual/en/refs.remote.mail.php
10 seconds of googling. SMTP is for mail relay, although it is the defacto protocol for mail clients to send mail, due to the Unix heritage of every box running an SMTP mail relay.
POP3 and IMAP provide mail clients' access to mail.

PHP Sending mail issues

I have an application to notify "friends" if there is an activity on their associates' pages.
This works but after series of tests seems it sends to the first few people and not to the rest.
No errors as the script redirects to mail sent page.
Now my host provider has a limit of 500 mails per hour for an account on their platform and the email list is over 3000.
Could this be the problem? What better options do I have?
Thank you.
Currently using PHP Mail Function
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 the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.
500 mails per hour should be the problem if your app takes that much volume. For a php server with usual configuration, mail() sends mails to local sendmail, then to local SMTP server where the host provider limits the rate. When the limit is reached, no one is on php's side to receive the error return mail.
I don't think it's hard to estimate the volume of your app. If you do need to send that many mails, consider rewrite your php function to use other SMTP server, e.g. Google Apps. Of course they come with their own limits however.

Is it possible to send an email from PHP without using the SMTP server

I need to send a newsletter to several thousands of subscribers with PHP.
The hosting service I am using allows me to send 300 mails/hour tops with their SMTP server.
They told me that if I send email with PHP without authenticating or using the SMTP server I won't have any problems with limits.
Is that even possible? Doesn't the mail() function in PHP use SMTP to send mail?
The mail() function will use whatever php.ini tells it to use which may be sendmail or may be an external SMTP server.
You have a few different options:
If they're not time sensitive, use their SMTP server and throttle yourself;
Alternatively, if they are time sensitive, it may make sense to authenticate against your own external SMTP server;
Finally, I'd suggest looking at a system like MailChimp or iContact. They'll let you send to anyone on your list and will handle bounces and unsubscribes for you. Even better, their servers have been whitelisted by ISPs, etc, so you're much less likely to have your messages flagged as spam.
My 0.02
On unix/linux, mail() is almost always configured to just use the local sendmail facility.
Technically speaking, you're still using SMTP servers, but not at your ISP. Sendmail communicates directly with the SMTP server responsible for incoming mail for each recipient.
While it's possible that your host has sendmail to route all mail through their SMTP server, it's unlikely.
I'd say just use plain old mail() and give it a shot.
The hosting company probably provides you with a SMTP server you can use, and it is that server that probably has the limitation. You can avoid the limitation by using another SMTP server (one that they aren't providing.)
All e-mail is traditionally "sent" using SMTP. You would need to configure your machine to use an external server.
http://email.about.com/od/emailprogrammingtips/qt/Configure_PHP_to_Use_a_Remote_SMTP_Server_for_Sending_Mail.htm
For a good general discussion of successfully sending e-mails from code, see this Coding Horror post. I noticed one of the comments mentioned the Postmark app as a paid alternative to using your ISP's SMTP server. I've never used it, so I don't know if it's worth the price.

swiftmailer email messages don't arrive

Hello I am trying to send email messages with swiftmailer version 4.0.3.
I get a returncode 2. And it seems the messages are sent, however they don't arrive.
I am using the sendmail transport mode
$this->psTransport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -t');
I get a return code of 2 and no exception happens.
Anyone familiar with this problem?
The SMTP Transport, Swift_SmtpTransport is without doubt the most commonly used Transport because it will work on 99% of web servers.
It is a more profissional way to do what you want. See the docs:
http://swiftmailer.org/docs/smtp-transport
SMTP Transport is simple and your messages are better recognized by the receivers because it's not your webserver sending your emails, but an email server already stabilished, with a known and approved ip.
Using PHP sockets to send mail is most of the times penalized by remote SMTP servers and detected as spam. I've suffered the same issue several times.
My advise is to use a SMTP transport method instead and send your messages through a recognized and validated SMTP sender server. If you are not sending too much messages per hour you can even use GMail servers, I use them very often for tests and small applications.

Categories