Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sun Aug 28, 2011 2:54 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
I've set up Google Apps to handle email for a few virtual domains on my Linode server. That is working just fine. However sending emails from PHP scripts using the mail function and PHPMailer are not working. Those functions just go away and don't come back - script processing stops - and no errors are reported.

I tried setting up the Postfix email server which I read might be necessary to get the PHP mail function to work but that didn't help or I didn't get it done correctly. There will not be any incoming email anyway because it is being redirected to the Gmail server so I'm a bit confused what to do next.

Any help would be appreciated. Thanks


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 3:26 pm 
Offline
Senior Member

Joined: Thu May 21, 2009 3:19 am
Posts: 336
Take a look at the postfix_install_loopback_only function here:
http://www.linode.com/stackscripts/view ... ScriptID=1

That's how I installed postfix to send email from my server and it's been working just fine for me.


Top
   
PostPosted: Sun Aug 28, 2011 4:13 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
I got the postfix configured for loopback only and PHP mail() still goes away and dies. Any other ideas?

On the PHP.net site someone says that apparmor can interfere with postfix. I haven't found much on configuring apparmor and what I found is wrong??

Quote......

I recently had an issue where the mail() function would work fine from the php cli but not from apache.

I eventually traced this down to the fact that I was using apparmor specifically, I configured apparmor to deny the apache user the ability to use /bin/dash

After changing apparmor to /bin/dash rix
and reloading the apparmor profile, mail worked

In other words, mail requires the account/program executing the script to be able to use /bin/dash


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 5:30 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
I'm not sure why PHP's mail() needs access to the dash shell; it should only really need access to sendmail. Maybe it spawns a shell and runs the sendmail command in the background. (postfix or sendmail, they are the same as far as PHP is concerned.)

Anyway, if I remember correctly, Linode's OS images don't come with AppArmor by default. But that was a few years ago, so things might have changed. Or you might have installed it yourself.

If you have AppArmor enabled, you can disable it on Debian/Ubuntu systems by using the following commands:
Code:
/etc/init.d/apparmor stop
update-rc.d -f apparmor remove

If you get an error message telling you that /etc/init.d/apparmor doesn't exist, then you'll know that it's not enabled. In any case, try again when you're sure that AppArmor isn't enabled on your server.

Also, set error_reporting to E_ALL | E_STRICT and enable error logging in your php.ini file, and restart Apache. This will give you access to the maximum amount of error messages -- down to the most trivial notices -- which might help track down the problem. PHP hides some errors by default, so you can't rely on what's shown on the browser.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 6:03 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
Thanks for your reply,

Apparmor apparently is not installed currently because the OS say so when I try to run /etc/init.d/apparmor stop.

I turned on the PHP error reporting as you suggest. When running the PHPMailer test script I got the following error trying to send smtp through the gmail server:

SMTP -> ERROR: EHLO not accepted from server:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. 1: Unable to send to: myaddress@gmail.com

Using mail(), sendmail, and the Qmail options on the PHPMailer test program, all report a happy outcome but I'm not getting any of the emails.

Also when I try sendmail from the command line it acts like it is working but I never get the email.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 7:19 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
As for the SMTP errors, but maybe you're connecting to an SSL port without telling PHPMailer to use SSL, or vice versa?

Qmail is irrelevant here, because postfix is not Qmail.

As for mail() and sendmail, is there anything interesting in Postfix's own logs? There are several files in /var/log (mail.log, mail.err, mail.warn, etc.) which can tell you whether the messages were received properly from PHP, and whether they were delivered to the target server.

Also note that many e-mail services will reject e-mails if your hostname doesn't match the reverse DNS for your IP address. If you didn't specify the correct hostname when installing Postfix, you should edit /etc/mailname and /etc/postfix/main.cf (the "myhostname" line) and restart postfix. Otherwise your e-mails won't even reach the spam box.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 7:34 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
As for the SMTP errors, but maybe you're connecting to an SSL port without telling PHPMailer to use SSL, or vice versa?

I think the telling is good, I'm using PHPMailer's own program for testing. The issued source looks very similar to the code I use on another server where I send email through the gmail ssl server successfully.

Qmail is irrelevant here, because postfix is not Qmail. Got it

As for mail() and sendmail, is there anything interesting in Postfix's own logs? There are several files in /var/log (mail.log, mail.err, mail.warn, etc.) which can tell you whether the messages were received properly from PHP, and whether they were delivered to the target server. mail.err and mail.log are 0 bytes long and mail.warn doesn't exist

Also note that many e-mail services will reject e-mails if your hostname doesn't match the reverse DNS for your IP address. If you didn't specify the correct hostname when installing Postfix, you should edit /etc/mailname and /etc/postfix/main.cf (the "myhostname" line) and restart postfix. Otherwise your e-mails won't even reach the spam box. When Postfix picked up the hostname at install time it was the same name as is in the hostname file. I took a look at main.cf and it's the same as shows with hostname -f. This issue confuses me on a virtual host server. I have 5 domain names I'm serving for and I need to send emails from each of those.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 8:03 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
As for the hostname:

The hostname used by Postfix should be the same as the reverse DNS entry in your Linode's "Network" panel. This does not need to be related to any domain names hosted on the same server, and it does not even need to be the same as the server's own "hostname -f". You can use Linode's default reverse DNS entry if you'd like. Afterwards, you should go to the DNS manager and add an SPF record to each domain, which allows your server to send e-mails on behalf of those domains. (An SPF record is just a TXT record that begins with "v=spf1" followed by a list of hostnames. Find out what you need to put in your SPF record to use your domain with Google Apps, and add your hostname to it.)

Often, test e-mails will be delivered even without proper SPF records. But the hostname & reverse DNS is very important.

As for the log files:

That's weird. There should be something in there if you already tried sending e-mails. Are you sure Postfix is actually running? Try restarting Postfix and see if you get any errors. Also make sure that you don't have any other mail server running on the same Linode. If you already have sendmail-mta or exim, it will conflict with Postfix.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 8:24 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
The reverse DNS lookup gives: "li220-189.members.linode.com"

hostname -f gives "scotthill.up_quark.com"

So, how might I go about fixing this?


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 8:33 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Put "li220-189.members.linode.com" in /etc/mailname

Also put the same hostname in the "myhostname" line in /etc/postfix/main.cf

Restart Postfix.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 8:42 pm 
Offline
Senior Member

Joined: Fri Jan 09, 2009 5:32 pm
Posts: 634
hybinet wrote:
Put "li220-189.members.linode.com" in /etc/mailname

Also put the same hostname in the "myhostname" line in /etc/postfix/main.cf

Restart Postfix.


you might get some servers thinking the numbers makes it look like a dynamic IP/home connection.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 9:56 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
glg wrote:
you might get some servers thinking the numbers makes it look like a dynamic IP/home connection.

If a home connection has a working reverse DNS entry, a matching HELO hostname, and a correct SPF record pointing at it, then any mail server had better accept the message. RBLs and SpamAssassin can take care of the rest.

Unfortunately, some services will spambox all your e-mails no matter what you have in your reverse DNS. I hope *.members.linode.com has a better reputation than any random domain, though.


Top
   
 Post subject:
PostPosted: Sun Aug 28, 2011 11:35 pm 
Offline
Junior Member

Joined: Sun Jun 26, 2011 6:42 pm
Posts: 32
I'm happy to report that I have outgoing email from within a php script using the PHPMailer package through ssl and the Google servers at smtp.gmail.com

Initially the email was being marked as from li220-189.members.linode.com and flagged as a problem by my receiving mail account. But after entering the TXT suggested here and by Google Apps: "v=spf1 include:_spf.google.com ~all" now emails are being marked as from who I want them to be marked from.

My understanding of this is very fragile and I still need to make a number of other domains and users work but as of tonight tonight I am a lot less frustrated. I have until November to move a bunch of domains to this Linode instance and make them work so I don't have to renew service on the old server network.

Thanks for your help folks.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group