I have a server with a webapp and a mail server (who use sendmail to route mails).
We need to migrate the webapp to an auto-scaling schema, so, I can't have the mail server in there, so, I'm thinking on leaving the mail server right where it is now.
So, to send mails I have different alternatives, I don't want to migrate to an external provider, the costs are to high (like 100 usd/m for mails + dedicated IP).
I'm looking for a way to connect my webapp PHP mail sending classes to this external server with sendmail.
Is there any way I can achieve this without creating my own API to send mails?
On Windows-servers you can change SMTP in php.ini.
Also, you can try to setup relayhost through Postfix (example here), but it seems like a simple API is the easiest and right solution :)
Related
This is an issue I've encountered several time and haven't yet found a decent solution for:
Sending an e-mail from a webserver on e.g. "domain.com", to info#domain.com which is hosted on an external mail server e.g. Google Mail
In my case I always send from PHP over Apache and often on shared hosting, but I can imagine this is the same case on other frameworks.
These e-mails always seem to be delivered to the local mail server, even if I set the MX records on that server to point to the right external mail server.
A solution for this is to use an external SMTP server, but this isn't always easy when you're working with clients that either need to set-up a new e-mail account on their server and provide the SMTP details or sign-up for a third-party SMTP server.
What is the solution for this? Is there no way around SMTP?
Most emai/MTA server "autoconfigure" themselves. They guess list of local email domains (doimans with locally hosted mailboxes).
In sendmail case you can turn it off adding the following line in sendmail.mc:
define(`confDONT_PROBE_INTERFACES', `True')
Documentation : cf/README - confDONT_PROBE_INTERFACES
I have had the same issue many many times (in my case using PHP on a LAMP stack).
Try/check the following.
If you are using cPanel or similar, set the MX records to the external mailserver (Google apps etc).
Set up an SPF record to allow your hosting website to send email (this way no need to configure SMTP).
This may not be applicable but if you are using something like phpmailer. Set the property $mail->isMail(); so it tries to use your SPF allowed local mail() function to send the email. Sorry for going off into very specific advice, but might help in your particular situation.
Worth checking there are not similarly named local mailboxes on your hosting box.
Hope this helps!
I am really confused on where to start with sending emails. I have search the web but the amount of content available for different packages and softwares has really confused me. I was wondering if anyone here had a simple or knows of a simple tutorial of how i can send an email using xampp.
Im new to using local host and so far have only used MySQL and Apache from xampp to load and view my php files for an application.
I would really appreciate it if anyone could help me start setting up XAMPP to send emails when i use the php.
Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!
is this link any good? http://www.websnippetz.com/2013/01/send-email-from-xampp-localhost.html
Many are using SendMail package with XAMPP but i can't find a download for that.
anyone tried anything which worked for them?
please help a very confused developer guys!
Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!
PHPMailer is not a server it is a library. People often recommend using a Mail library because the built mail functions are very low level and hard to work with. Because they are modeled after using sendmail from the commandline.
If you want to send via SMTP, use attachments, or other things it can be difficult or impossible to do with mail() directly.
Personally I recommend using SwiftMail over PHP mailer. IMO, it's more modern, easier to use, and has a better API, and depending on which PHP F/OSS projects you are used to using or contributing to its more common and the standard.
Overall there are 2 parts to sending mail from PHP:
Setup of the actual mail server on a system (local or otherwise)
The configuration of PHP to use that mail server.
To setup the mail function you need to install and configure a mail server locally in order to fulfill item (1). This should already be included and set up on OSX. So to fulfill item (2) you need to configure PHP via the INI to use that mail server by changing the sendmail_path.
Now if you want to use a library, which I recommend you need to get that source into your project and then use it appropriately. For the example we will use SwiftMailer, with SMTP transport via a gmail account:
require_once 'PATH/TO/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
->setUsername('user#gmail.com')
->setPassword('secret');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('My SMTP Message')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receipient#domain.com', 'other#domain.com' => 'A name'))
->setBody('Plain Text Message Body');
$mailer->send($message);
To send emails from your localhost your need an Email-Server like postfix or Exim or you send your E-Mails over SMTP what is described on that site from your link.
The easiest way is to use an abstraction layer like Swift Mailer
http://swiftmailer.org/docs/sending.html
Here you have a lot of possibilities to send E-Mails. Another solution is to install a local Mailserver and fetch all sending E-Mails. In MAMP Pro for example you have an integrated Mailserver.
http://blog-en.mamp.info/2009/09/how-to-sending-emails-with-mamp-pro.html
I'm building a site on my home computer using MAMP. The code I'm using employs the PHP mail() function to send emails, but whenever I test it, the mails aren't getting sent.
My computer is connected to the net, but I'm wondering if there's something about local hosting that prevents mails from getting sent. I'm not getting any kind of error message.
Any ideas?
PHP can send mail in one of two ways.
The first, and the default on non-Windows systems, is to use the local mail transfer agent installed on the system. This would be "sendmail" or an application compatible with it, the most popular probably being postfix.
The other is to connect via SMTP to some mail server.
You will either need to install a mail transfer agent on your local system (and set it up correctly), or edit PHP's configuration to specify an SMTP server address and port.
Yes, there are things that could block locally hosted mail. For one, your ISP could block SMTP to servers other than the ISP. ask your ISP support if they block SMTP... Or try telexing so someone's MX port 25 and do you get a response?
If your ISP blocks smtp you can still send the mail, but first you must relay that email through a hosted email server like your ISP mail server. This process is called 'smart hosting' and you can search for more info.
Even if you are not blocked on port 25, many sites will refuse or lose smtp traffic that originates from a dynamic or residential IP address, so again the smart host suggestion.
Also I suggest not using the built in mail() function in PHP... Use something that replaces and improves it like http://pear.php.net/package/Mail or http://sourceforge.net/projects/phpmailer/. Again, use the SMTP method as it is way more reliable than direct sending or calling Sendmail.
It is important to confirm this problem, doing SMTP manually over telnet. That way you isolate the problem from PHP. I did ISP support for years and saw this question lots. Most people setup php and mail correctly but get stuck on a background network issue with SMTP.
If you have Wireshark installed, it can record network traffic and you might see the actual SMTP traffic, for example the remote server may be refusing your connection. Wireshark is helpful but not required to solve this though. Good luck.
You need to setup SMTP server in order to be able use mail function, or you can use PHPMailer class, with it you can avoid using mail function and setup problems, PHPMailler need socket extension to be loaded in order to function correctly.
Currently there are no MX records pointing to my server. Will I need to change any MX records to get php sendmail working? I only need php to be able to send mail (on multiple virtual domains...). Also do you recommend sendmail or postfix? thanks...
Postfix is much easier to configure, so I say Postfix any day.
You won't have to change any MX records just to send mail. Just configure Postfix properly and you're good to go.
I would just use a library the allows you to send from a remote SMTP server. Typically i use SwiftMailer but in the past phpMailer has done the job just fine...
I want to write an email transfer service and need a MTU replacement of sendmail/postfix.
I'm not looking how to deliver to a transmitting SMTP server (like a postfix listing on a SMTP port). I also don't need the receiving part of the server, bounces etc. would go to a different existing postfix.
All of it in pure PHP. SMTP is a pretty easy protocol but this would require access to the MX DNS record and other lot of details that need to be taken care of.
Why do i need this? Because most shared internet providers have insane low limits for sending out emails like 500 per day. Thats almost nothing if you want to setup even the lowest traffic email list.
EDIT: Please Note: The code needs to connect to the receivers SMTP server and deliver the message with an adapted header set (removed BCC list, added Path route). If you see a SMTP class less then 5000 lines or requires you to configure a SMTP hostip and port then this is not the stuff i'm looking for.
It needs to do all the stuff sendmail is doing just as a PHP library.
I use Pear's Mail class.
EDIT
After re-reading this, I see there's more to it than just a library. You are asking to send direct to the remote MX.
Why reinvent the wheel? Set up an instance of postfix on the server, which only listens to connections from the web server... and let an MTA do what it does best. Hand off the messages from php to a real mail server and move on.
In the case of ISP's that block outbound port 25 and force the use of a smarthost, this also allows you to restrict the rate of messages sent to the smarthost.
Lastly, sending straight to the end MX from your php script is a bad idea, because if you send to me, I'll never get it. I and many other sites use "greylisting" to reduce spam, which denies all initial requests with a 450 temporary error. Real MTA's will try again, but unless you implemented a delay queue and try again, your message will never go through.
We use http://sourceforge.net/projects/phpmailer/ to do SMTP email from PHP
SwiftMailer is the only library you'll need.
Try Zend Framework component Zend_Mail (you can use the component independently of the entire framework).
Here is something I wrote. It's quite minimal and I don't know how well it performs, but I wrote it with the intention of replacing sendmail, meaning that it will take a message, lookup all the MX records for the recipient domains, contact those mail servers and deliver a message for the corresponding recipients. It worked well enough for me at the time.
https://github.com/denvertimothy/ThriveSMTP
It's been a long time since I've used it, but I threw it up on Github just now.
I used http://www.mailerq.com/ which works cool. Its a queue based mail transfer agent. It requires rabbitmq.
It provides multiple worker as well.easy to store in database.
It provided management console as well.
worth to check it