Configuration issue when sending email on Mountain Lion using Postfix - php

I've been stuck on this problem for the whole afternoon and tonight but cannot find an answer. But I believe it's some easy configuration issue on Mountain Lion.
I want to send out email using PHP, and I installed PEAR:Mail package; that all works fine.
But when I try to send email in PHP, it returns me no error; but email not received.
I further dig into the problem, found that I need to properly set up my local postfix mail program. I therefore following these articles to setup:
http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/#comment-259; when that didn't work, I followed that one instead: http://slashusr.wordpress.com/2012/02/14/enabling-postfix-for-outbound-relay-via-gmail-on-os-x-lion-11/.
The basic steps in the blog post is to teach you how to send out using GMail by doing some settings in /etc/postfix/main.cf
But when I test it in terminal with command:
date | mail -s test <my_email_address>
Nothing happened, except that when I type "mail" again, it prompted me with a new message, telling me this error (part, only what I think to be useful):
: host smtp.gmail.com[209.85.225.108] said: 530-5.5.1
Authentication Required. Learn more at 530 5.5.1
http://support.google.com/mail/bin/answer.py?answer=14257
aa4sm11414435igc.15 (in reply to MAIL FROM command)
--1306515822A0.1347279593/songyy.local
Content-Description: Delivery report
Content-Type: message/delivery-status
I visited the link given in the error message, but it's irrelevant.
I'll very much appreciate if anyone can give me some advice on this.

I want to send out email using PHP, and I installed PEAR:Mail package; that all works fine.
Very well. Then you must have a "mail relay server" address, to whom mails get sent. It is usually supplied by your Internet provider.
You must configure that address into Postfix, as relayhost. No other setting is usually necessary.
The recipe you followed is much more complicated because it entails Postfix connecting to GMail and authenticating as a user, all through TLS/SSL. To do this you must store the username and password to your GMail account (or another account created for that purpose) in the postfix passwd file.
The fact that GMail complains of "Authentication Required" tells us that either you skipped this detail, or you stored the wrong password; so GMail can't go through the email forwarding process.
Note that if you only use plain SMTP, the outbound emails will be sent in the clear (as opposed to GMail use of SSL encryption).
Check out the system logs if you need to see in detail what happened to your mails.
Another thing to watch out, you say:
I specified the file by setting: smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
This file expects to be in a specific format (documented in the file itself). After that, though, you have to convert the file into the hashfile, which is the same filename but .db extension. Some distributions do this automatically, otherwise you need to manually run the postfix utility postmap (or in a pinch, makemap). In your case:
postmap -c /etc/postfix /etc/postfix/sasl_passwd
This will take /etc/postfix/sasl_passwd and hash it into /etc/postfix/sasl_passwd.db, which is the actual file Postfix checks. It is possible that this particular detail was not covered in the tutorial you followed, and Postfix is still checking a .db file which was built from the previous (and empty!) sasl_passwd.
You are quite right that by specifying user, host and pass in PEAR, you are effectively overriding Postfix configuration - I think the Mail package performs so-called direct-to-MX exchange, and thus does not even need Postfix at all.
The log files should be specified in main.conf and are usually /var/log/messages or /var/log/mail(.something).

Related

How to enable mail() function

I am trying to work with a shared host in which the mail() function was disabled (I can see that on disabled functions on phpinfo()) by someone that I don't know.
All I have access is the root folder for the site files in the ftp, so I can't edited the php.ini in /etc/ neither restart Apache (I know is a linux based OS).
Is there any way I can enable it by a secondary php.ini or ini_set()?
EDIT: I am aware of PHPMailer. I was trying to use it but it was being block as well. That's why I started trying to use mail(). Just to see if it would work
You need to get a new host or upgrade to some different plan.
However you can go ahead with mailgun(https://www.mailgun.com/) which is very cheap and no cost to set up.
You just need to link your credit card for a safety but they never charge you unless you pass 10,000 emails per month(https://www.mailgun.com/pricing).
There are other solutions as well like mandrill or sendgrid. However, Mailgun is almost free unless you are using more transactions emails.
You can find the official mailgun php package in here : https://github.com/mailgun/mailgun-php
You need to check if curl is installed in your server though.
Secondly, trying to send emails directly is not a good practice. Most of the times they will end up getting in spam folder. Use SMTP and use PHPMailer Extention.
Steps to do so :
1. So to cpanel and go to emails
2. Create a new email account and add a password
3. Click on configure mail client related to the new email address you have created
4. You will get 2 tabs, SSL configurations and NON SSL configurations
5. You can choose TLS, copy the outgoing host, email and password.
6. Now install phpmailer and enter the above credentials and try sending email.
7. Also as a safety, go to authentication in your cpanel and check if any issues are mentioned for emails just for safety.

Is it possible to configure sendmail to use SMTP authentication by default (for use with PHP)?

I am maintaining an old PHP application and I would like to configure it to use Mandrill for outgoing email. Mandrill, of course, requires SMTP authentication. The application uses PHP's mail() function directly.
Is there any way I can configure sendmail (or an equivalent service) to send using SMTP authentication by default (with the credentials for Mandrill), without having to replace all the mail() calls throughout the application?
I saw some other answers about SMTP configuration in php.ini but that only works on Windows, so I believe the only PHP setting I could change that would potentially be useful is sendmail_path, which defaults to sendmail -t -i. I was thinking maybe I could point it to a shell script instead but I'm not sure how to go about that or whether it would work.
UPDATE
Thanks to #mti2935's answer, I was able to get this working. I had trouble getting sSMTP to work (got the error "send-mail: Cannot open smtp.mandrillapp.com:587" even though there was no firewall blocking it) so I followed the second link and set up MSMTP. I had to change the tls_trust_file setting to /etc/pki/tls/certs/ca-bundle.crt (note: I'm running CentOS 6). Also, the sendmail_path PHP setting recommended in the link didn't work for me; I had to change it to "/usr/bin/msmtp -C /etc/msmtp/myconfig -t" (and restart Apache since I changed this in php.ini rather than in an .htaccess file...note that the config file can be called whatever you want; choose your own name in place of "myconfig").
Also, when testing, be sure to specify a "From" address, otherwise some destinations including Gmail might reject the message.
There are a number of lightweight replacements for sendmail that can be used to relay outgoing messages through a remote SMTP relaying server, such as SSMTP, MSMTP, and Nullmailer. By replacing /usr/sbin/sendmail with one of these, you can relay outgoing mail sent from your PHP scripts through a remote SMTP server, without making any changes to your PHP scripts that use the PHP mail() function. These replacements simply handoff the message to the relaying server - the don't handle incoming mail, they don't manage a queue, etc.
See:
http://itekblog.com/ssmtp-a-gmail-sendmail-relay-replacement-for-linux/
http://www.emanueletessore.com/how-to-configure-msmtp-as-a-gmail-relay-on-ubuntu-server/
http://untroubled.org/nullmailer/
Another option may be to continue using sendmail, configured with a smarthost. See https://serverfault.com/questions/41448/fastest-way-to-allow-sendmail-relay-through-smarthost
Swiftmailer is a good option. You should also take a look at Zend2 Mail. I used this on a small project and it fit the bill nicely.
PHP Storm has a pretty cool search and replace function. If you just search for let's say "mail(" (without the quotes) you can manually go through the results and confirm before replacing them. Or you can do a replace but before it replaces each occurrence, you can confirm it.

How to send myself an email with php, Windows 7, WAMP server? need SIMPLE solution

I have spent the last 15 hours trying to figure out a simple, free way to send a simple text email via a php script when a form is filled out on a html page. I don't care how it looks, as these emails are only going to be sent to me (at most 15 a day). I don't need anything except a simple email to me when the form is filled out. I understand everything except I cannot get past:
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini
What i have tried:
Playing around with the pear mail extension and using smtp.gmail.com
Downloading countless smtp mail server applications.
Using my ISP smtp and port 25: smtp-server.wi.rr.com.
Using PHPMailer.
Using the windows SMTP server.
Although all of these things should work... I am apparently too dumb to figure it out. I have read every sentence on the subject on the internet and have tried to follow instructions, but each time I try something else, I just run into more problems. Someone PLEASE give me a simple fix to this, so I can never look at PHP mail stuff again.
If you're sure all these settings are correct, you should check your firewall. If all else fails, try sending a mail from a mail client (or make an attempt using Telnet!). If this succeeds, than you're doing something wrong in the PHP configuration, or the way you send the e-mail. If sending fails with other clients too, than the problem lies in the ability to send e-mails from that computer at all.
Your own ISP should work fine. Remember that most ISP's don't require you to enter a password. Only the smtp server will suffice in that case.
Folks.
After many hours of trying I found that:
You don't need additional tools like mailservers or pear additions. These only provide additional potential security leaks that you have no control or insight over.
To get mail function to work on localhost, all you need to do is change the php.ini file.
I just checked my outlook account settings and copied those to the php.ini file.
So SMTP server, port, username and password.
Now,
You may think it does not work but
You should know that many mail clients reject emails if the From field has a different domain than the actual domain an email is received from.
So if the php.ini file contains for example
smtp.ziggo.nl
Be sure that the header contains:
From: info#ziggo.nl
So for making universal code on both localhost and remote host, I check for the existence of a file that I only have locally (e.g. z_local) and set the headers accordingly. If the local file does not exist I must be on the remote ISP and choose the header "From: info#remotesite.com"

Mail relay and php mail

I have a VPS server at UltimateHosting.com and requires that I use "Smart Relay". I cant seem to wrap my head around how I setup php to be able to use mail relay.
Here is an article they have on Smart Relay:
http://support.ultrahosting.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=142
The server is using cpanel and exim
I sent the following support ticket:
How do I configure the server to send
mail using php. I am writting a script
that will send the users passwsord
usigng PHPs mail function. However the
emails sent are never delivered. Does
this have to do with "smart relay"?
Any guide on how to configure this?
Response was:
While we do not provide scripting
support of any kind, if you simply
ensure the smart host is hard coded in
your script (no authentication is
necessary) the email should be
forwarded accordingly.
If your script uses the server's SMTP
server to send out email, you'll have
to ensure the MTA is configured to use
the smart host
.
Could anyone please clarify what I need to do in order to fix this?
I got the answer on ServerFault see https://serverfault.com/questions/188840/configrue-exim-sendmail-for-relay for details.
In short, I needed to change the default generic hostname and apply the route relay

A couple problems re: CodeIgniter emailer

I have some problems with the email system for CodeIgniter:
First, the emails I send out (registration, confirmations) are getting caught in standard spam filters in gmail and other mail clients. How do I get around this? How do companies like Facebook get their emails through consistently?
Second, the mailer is working locally but once we deploy it it no longer runs (doesn't send emails) but all the other forms run just fine. Anyone ever run into a problem like this?
Thanks for all the help!
I can't really answer your first question - it's not specific to CodeIgniter. You just need to make sure your email doesn't look like spam. In short - there's no way of guaranteeing your e-mail will not end up in a spam filter.
As for the second question, I expect your production server needs to be configured properly for email. You probably need to configure CodeIgniter to send email properly. I would suggest setting up an SMTP server (or using an existing one) rather than using the standard PHP mail which I think CodeIgniter uses by default.
Regarding spam, most organisations are very secretive about how they prevent spam (not wanting to publish information which helps the spammers) and in some cases they don't actually know - an obvious examlpe of this is bayesian filtering - but, for example, hotmail use a completely unaccountable army of volunteers to manually classify emails.
Do and get a copy of spamassassin and try to reverse engineer how the standard rules work. Obvious things to check are:
1) AVOIDING LOTS OF CAPITALS
2) don't mention the 'V' word
3) make sure you've got a current and restrictive SPF 1.0 policy published
4) make sure your sending from an address which has A and PTR DNS records
5) Do provide a reply-to and from email address which use your domain in the address
the mailer is working locally but once we deploy it it no longer runs
doesn't send emails
Which? These are 2 totally seperate things. If the code is falling over (if so why have you not provided the error details) then its likely a PHP version issue or a problem with the connection to the MTA (or the PHP mail config).
The latter is a problem with the MTA itself.
99.9% of problems reported as PHP mail failures have nothing to do with PHP and are problems with the MTA.
Enabled detailled error reporting for your MTA and see where it is failing.
C.
You may have to configure the email on your server differently than your local development environment. I've had to in the past.
There are two basic ways that PHP can send mail:
Via a UNIX program called "sendmail" (only on non-Windows servers and only if it is installed - check with your hosting provider)
Via a SMTP server.
If you've configured CodeIgniter to use SENDMAIL, check to ensure that the Sendmail path is correct. Your hosting provider usually provides this somewhere in their online documentation.
If you're using SMTP, you need to make sure that your server can contact the SMTP server. You can do this by logging into the server via SSH and typing "telnet your.smtpserver.com 25". If you get an error message about not being able to connect, you know you have a problem with your hosting provider connecting to your mail server.
I've been able to diagnose this problem by enabling logging on my production server (http://bit.ly/4pprd6) and adding log_message('error', $this->email->print_debugger()) right after I attempt to send a message.

Categories