I am pretty new with the options of sending email via PHP code. The options available are sendmail, postfix, and PHPMail. If I use sendmail and postfix this means that I have to use PHP's mail function. I don't know about PHPMail. I will be sending email across domains (hotmail, yahoo, gmail, etc). It's an automatic email sent to a user's email after they completed something (say a registration). What do you guys think about this?
I've tried setting up sendmail in my Ubuntu server, but had some difficulties in setting it up. So that's why I am probably looking for more options.
You need a MTA (mail transport agent) on your machine (sendmail, postifx, ...) or you can connect to a mail provider like gmail using SMTP.
PHPMailer might be a good class for sending emails if you're not using any framework.
PHPMailer is on Google Code and GitHub.
You should have a pretty easy time setting up sendmail on ubuntu
http://ubuntuforums.org/showthread.php?t=196112
This gives the basics it takes to get sendmail installed.
If you are running this server from your house or some non-datacenter there is a chance that your ISP is blocking the port numbers you need such as port 25.
Read through that thread and it should give you some good suggestions for issues you may have.
Related
Setup:
Ubuntu 16.x, Postfix, PHPMailer
SocketLabs (mail relay service) - to send out server emails
Union Solution Exchange Server - to send and receive formal email from outlook
Im trying to send out emails from my ubuntu linux server that contain simple form data (name, message, phone etc).
I have been trying in vain to send emails from my PHP to emails, they send, but they get blocked as spam/junk.
I've recently switched mail services (from zoho to a solution union exchange server) and I cannot get past barracuda (even modifying whitelists / spam settings etc) with my own mail, but I can see them as junk in my hotmail. (cannot not send from mailserver#potlickers.com to support#potlickers.com). They get immediately canned and not delivered.
Solutions Union said I was spoofing the emails and I cannot whitelist my own domain I'm using and sending from? Ok. They suggested buying another domain. I now own potlickers.net.
They also mentioned I should take that domain and use it to send my emails via open relay (again socketlabs).
So, if my webserver is setup on a fqdm such as potlickers.com, and i send the mail from that server, how do i setup the correct architecture to send mails from potlickers.net to the open relayserver so my emails are free and clear and not spoofed?
Can i configure postfix to send mail from potlickers.net even though its hosting on blah.potlickers.com?
I understand to also add dkim and PTR.
Help stackoverflow1 - your my only hope. TIA much much mucho thanks.
So I think I got it.
Reconfigured postfix as a satellite. Pointed to smtp of relay mail server. Removed all SMTP settings in PHPmailer that point to server, and credentials.
Fire away - works like a charm.
Satellite server has the new domain potlickers.net versus the webserver domain potlickers.com
Seems to work ok for now. Will update moving forward.
I'm switching a web app over to AmazonSES. We're using PHP 5.3, PHPMailer, and we tried using the AmazonSES pear package but for some reason it was unbelievably slow on the live server. We switched to the Amazon perl script thats use sendmail instead and it's much faster.
However, the Undisclosed Recipients feature (built in to AmazonSES pear code) was no longer available. No matter what I do, the only thing I can get working it by addressing an email as "To: Undisclosed Recipients <workingadd#domain.com>"
The problem is that the working address HAS to be there: php's mail() func require it, phpmailer requires it. The problem is, using noreply# fails, but workingaddress# works. While the recipient list is protected, we end up getting all the emails at that address.
However, the Amazon code managed to send mails without a primary address. I can't find anything in their code that suggests the answer, nor on the net.
Please help!
Oh, You want to send mail, Please careful that MTAs don't you as SPAM, if you want to know all of its rules please read all of rules of SpamHaus
Set up an interim relay server with postfix or sendmail. Have your application send emails to that server. Have that server connect to amazon and send the mail to it. Let it handle the authentication, etc. It works extremely well.
--David
I'm getting a 'could not instantiate mail function' error from PHPMailer. From reading around, I understand this to mean that the PHP mail() function isn't working for some reason.
The results of phpinfo() for the mail settings are:
To me, this means that mail() should work and that port 25 is open. Is that right?
Is there anything else I can check to make this work please? I had a look at the docs for the mail() function, but I couldn't see what exceptions it threw and how I'd print them out to screen. I did a:
mail('name#email.com', "test", "test") or die("Doesn't work");
type test, but that's my error message and I could do with something a bit more helpful.
Grateful for any help on this.
Many thanks
it doesn't mean port 25 is open, it just means that PHP should use port 25 for contacting the SMTP server. You don't state what OS you're on, but note that sendmail would be a unix-only thing, and will fail if you're on Windows.
That list merely show you your current settings. That doesn't mean that they are right. :)
Your localhost is probably not configured to be a mail server. Set the smtp server to a real server than can be reached from your PHP server.
I am probably way off, but check to see if sendmail is installed, maybe it is malfunctioning. This depends on your OS.
The settings from phpinfo() show the PHP is set up to use SMTP but it does not mean that you have an SMTP server set up on the machine. Your error message suggests that one is not setup.
Good luck
My answer would be - don't send emails by calling Sendmail. The sendmail method (or ANY local method) is a mess of pitfalls... and even if you get past those issues, the bottom line is many spam filters (at the places you send mail TO) simply do not like this type of mail.
To provide just a little detail why the sendmail approach is bad, your sendmail daemon is unlikely to be configured to have an SMTP HELO which matches the reverse DNS of your IP address. Your webserver is unlikely to have valid reverse DNS matching a standard hostname. NO reverse DNS at all is bad, as is rdns like 123-123-123-123-static.someisp.com. SpamAssassing will flag such "unconfigured or default reverse DNS" hosts for example.
Fortunately you don't need to understand or fix everything I just said. The much simpler to accomplish (and easier to test/debug) is to GATEWAY your emails through a working SMTP mailserver. To do this:
1a) Install PHPMailer http://phpmailer.worxware.com/ ... OR
1b) Install the PEAR Mail() library http://pear.php.net/package/Mail
Either 1a or 1b will replace the limited "mail()" function in PHP. These replacements support both SMTP, and Authenticated SMTP.
2) I suggest using Authenticated SMTP over plain SMTP. Either works, but with authenticated SMTP you can literally send mail through another mail server just as IF your script were a local email client like Outlook. This has major benefits. For example, if you are a company sending mail, your mail is more likely to be trusted by remote/target mailservers, since your mailserver has a good reputation and (hopefully) proper reverse DNS setup. But if you originate the email off a webserver, you have none of that (and if you use shared webhosting, you will inherit the email reputation of whatever other sites run on your webserver IP.).
I am trying to send an e-mail from localhost but am getting the error:
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set().
Does this mean i need to set up a local mail server?? and if so how and which one is easiest.
Thanks in advance
Paul
This is what I use, but it's for testing purposes only:
http://www.toolheap.com/test-mail-server-tool/
There's almost no configuration, and I got it to work right out of the box (on Win7) after failure with several other mail servers. It does not send the actual mail, but stores it as an .eml file. This is great for testing mailing lists for instance, where you don't really want to send the 2000 emails, but want to get a realistic result from your application.
It might look like garbage, but it's been working great for me.
Yes, it does, and if you want to send mail to an outside email address (and not a user local to the system, it is annoyingly difficult).
Most hosting companies (e.g. GoDaddy) have this setup for you, so PHP's mail() function works without you needing to do anything.
If you're configuring it on your own system, you might want to consider (a) configuring sendmail to use an alternate SMTP gateway (I frequently use Gmail) or (b) a complete alternative to sendmail (Zend Mail looks promising.)
If you are using Linux, there is usually no need to set up a a mail server,
If you are using Windows, yes, you do need to set up a mail server
If you are interested in just sending mail, you can by SMTP protocol use any SMTP server. Here is a tutorial to setting up PHP to use a remote SMTP server.
Yes, you need a mail server to be able to send mail, but even if you do, you are not going to be able to send to addresses outside of you local network as mail from your computer will be blocked by all recipients for spam reasons.
You could use the pear mail function to connect to an external smtp providor like gmail to send the mails for you. More info here and here.
smtp4dev is in my opinion the best tool for capturing local SMTP traffic on Windows.
It listens SMTP on localhost port 25 and pops up a notification every time a new mail is posted (it doesn't actually forward the mail to its recipient). You can then open the message in your favorite mail agent or save it to a file.
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.