swiftmailer email messages don't arrive - php

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.

Related

Laravel 4 Mail - failed SMTP on server, switching to mail method

This is quite strange as email sending using my Gmail SMTP server works in my localhost, but when I deployed it on a VPS, it wouldn't work at all.
I can't find any issue as to why this is happening, the configuration looks normal (SSL port 465, Gmail SMTP server). I'm using Laravel 4.0.9 so I thought of upgrading to 4.1/4.2 to use the Mailgun feature (not sure if 4.0 can use Mailgun?)
Anyway, for a quick fix, I just switched to mail method for email sending. Since this works well for me, my question is that whether there is any tradeoff of using mail instead of SMTP on Laravel? The delivery seems okay as it got to my inbox, but what about the long term?
Any thoughts would be very much appreciated :)
When using the built-in mail function you don't benefit from additional features such as DKIM and the SFP configuration for your domain may not allow hosts other than your SMTP mail server to send mail for your domain, all of this makes the mail you send that way look like spam to other servers.
While you may not have issues with some providers, try to send mail to some more restrictive providers such as Outlook (ex-Hotmail); I'm pretty sure all the mail you send there will be automatically marked as spam because of the issues described above.
PHP mail may be faster since you don't have to connect to your smtp server, but it's not better. In the long run, SMTP email is the only way to guarantee that your email will arrive in the inbox of your receivers

Are there any SMTP servers written in PHP or Go?

I don't mean SMTP/IMAP clients, I mean a working SMTP server that can both receive and send email.
There are lots of examples of partial PHP and Go SMTP servers that only listen for SMTP connections - aren't there any which show how to send mail?
I'm really interested in learning this second half of the Simple Mail Transfer Protocol. I understand that there are a lot of bad servers which vary from the standard - but I want to learn how the whole protocol from start to finish is implemented.
I think you misunderstand how SMTP is supposed to work. Here is a simplified version:
The Mail User Agent (MUA) queues a message for delivery by sending it to the Mail Submission Agent (MSA).
MSA connects to the Mail Transfer Agent (the "smtp server") over SMTP.
The MTA then uses DNS to lookup the MX record for the recipient's domain. It then contacts the recipient's MX server as a SMTP client.
The MX server accepts the envelope; it then forwards it to a Mail Delivery Agent (MDA).
MDA then puts the envelope in some message store where some IMAP or POP3 server reads messages. The MUA then connects to these servers to retrieve the message.
The entire process uses three main commands. MAIL, RCPT and DATA.
MAIL = Envelope information, bounce addresses, etc.
RCTP = The recipient.
DATA = The payload.
The SMTP server responds - much like HTTP actually, with error codes and based on that, the MTA knows what to do with the envelope (its a bounce back, so send appropriate reply, etc.)
In this process there is no such thing as "retrieve email" (ignoring ETRN for a bit); as SMTP is purely for email transmission and not retrieval.
I found a full SMTP server written in PHP - even includes a nasty open relay.
$ sudo php php-smtp.php [ip-address] [port]
There is no "second half" of SMTP, just the protocol. If your MUA interacts directly over TCP with the mail server (rather than using a helper program like the /usr/bin/sendmail binary found on most Unixes), then it uses the SMTP protocol. The MTA uses the same protocol to talk to other MTAs when delivering the mail. It may use a larger set of the available verbs, depending on the circumstances.
Seeing the code of a PHP or Go implementation of an MTA would show you how one person/team has implemented the SMTP protocol.
THere's a PHP smtpd server that just processes mail - https://github.com/flashmob/Guerrilla-SMTPd
and a port to go
https://github.com/flashmob/go-guerrilla
There is a non blocking SMTP server writen in PHP on top of ReactPhp:
https://bitbucket.org/david_garcia_garcia/smtpserver
It is designed for the end user to have custom Authentication and Delivery implementations, the rest of the SMTP behaviour works out of the box.

handling bounce email w/phpmailer

I have a webpage that sends out emails using phpmailer. I set the host to 'relay-hosting.secureserver.net' the mail->sender, mail->from and mail->addReplyTo all to the same address, which is the address that I want the bounced email notifications sent to. This email address in also with the same host and the smtp host. When I put in a bad email address I don't get a notification that is was not delivered. What am I doing wrong? Thanks
PHPmailer does not handle receiving emails. It's purely a library for allowing PHP to talk to an SMTP server for sending emails. It has absolutely no support whatsoever to act as a mail client (e.g. receiving).
PHPmailer has no way of knowing the email bounced, as the bounce occurs LONG after PHPmailer's handed the email off to the outgoing SMTP server. IN real world terms, PHPmailer takes your letter and walks down the block to drop it into a mailbox. The bounce occurs later, when the letter carrier brings the letter back with 'return to sender' stamped on it - PHPmailer is not involved in this at all.
Your options are:
1) Use PHP's imap functions to connect to an existing pop/imap server and retrieve emails that way
2) Use a .forward or similar redirect on the SMTP side to "send" incoming email to a PHP script.
I know this is an old and answered question, but for those who may find this post later with a similar problem you might be able to solve this by going to your smtp mail relay service. If for example you use jangosmtp there is an option in your jangosmtp control panel to either hard code the address to which bounce reports should be sent or to always send bounce reports to the From address.

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.

Logics between php mail(), sendmail(), using SMTP in 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.

Categories