CentOS need to configure SendMail so that PHP Mail() functions sends to external server

I am not very good with Linux but CentOS 6 is what I chose to do our intranet with. And it has been awesome for speed and reliability. I have several PHP applications running on it that have been using PHP Mail() to send out notices.

Unfortunately, 3 times our Exchange host has stopped those messages because of changes to settings by the cloud host.  Really annoying.  

So, I setup my own relay server out on the internet. It has worked for a couple of applications that have a place to create SMTP settings. My real issue is that some just use the PHP Mail() function in several scripts.... how do I point that to my outside SMTP server. Feelin' dumb...

Thanks for any help!
hydraziAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
The traditional answer is "Use PHPMailer."  I did this a few years ago for my church and it worked well.  Probably works better now, but I don't have any current code samples.  Still it's worth a look, I think. ~Ray
0
hydraziAuthor Commented:
Hey Ray,

Yes, I see a lot of answers like that but unfortunately that means I have to track down the use of mail() in these apps and fix them.  I did not create a few of thse and it might prove to be difficult, more difficult than I have time for.  

I will look and see, but I am hoping for a simpler answer.  :)
0
Dave BaldwinFixer of ProblemsCommented:
The PHP Mail() function on Linux only points to a local SMTP server, not a remote one.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

arnoldCommented:
Look at php.conf there you can define whether it will use a local smtp or a remote, just note that a remote has a larger overhead as well as mail() lacks the error detection/correction. I.e. If there is an issue, the mail may be rejected and will be discarded.

The issue you seem to have external to your setup.  Unless you can identify the cause for your issue, you will be chasing .... To resolve it.
0
hydraziAuthor Commented:
OK, going to look around and get this closed up today.  Sorry for the delay
0
hydraziAuthor Commented:
OK, I am looking in the PHP.ini since I cannot find the php.conf.  I do see a place to make mail changes, but one says it is for Win32 only and I am on CentOS.  The other just wants to know where sendmail is.  Where would I change this in Sendmail?
0
arnoldCommented:
If you comment out the sendmail location at the end of the file. and use the win32 options, the php mail() function will establish an smtp connection to the smtp server you have listed in the win32 section.

if you do not have sendmail installed, I would suggest you use yum install postfix
and then point to /usr/sbin/sendmail -oi -t

It is simpler and there is no overhead for the SMTP session.
0
hydraziAuthor Commented:
I am lost in a rabbit hole here.  
I made changes to my php.ini file, adding in my SMTP host, Port number, as well as username and password.  Then I commented out the sendmail location.

Unfortunately.... it did not work.
I tried putting in PHPMailer, but I think I am trying to pull it from a bad directory.
I am going to copy the class files to the same folder and see if I can get it working that way.

Currently, I have had this system down for 2 days and people are carrying pitchforks.  :)
0
arnoldCommented:
Does your smtp host require authentication?

Your best option is to install postfix which is much simpler to configure.

chkconfig postfix on
/etc/init.d/postfix start

then revert the last changes and use /usr/sbin/sendmail for sendmail (while you have a different mailer, to maintain backwards compatibility all mail servers have/place a reference in /usr/sbin/sendmail.

Copying things ......... might not resolve what you have.

After postfix installed and started, look in /var/log/maillog for any errors.
what is the hostname of your system?  did you leave it as localhost.localdomain?
0
hydraziAuthor Commented:
Yes, smtp require authentication.

I will install postfix.  At this point, it can't hurt.

I can change that hostname back to localhost.
0
arnoldCommented:
Do not change the hostname.  Just trying to see what your hostname is.
0
hydraziAuthor Commented:
OK, so I already had Postfix installed it seems, so I started it up and ran CHKCONFIG
I left with WIN32 items in there, but put the sendmail -oi -t as you specified.
0
hydraziAuthor Commented:
Alright, my maillog shows it is using Postfix but set to localhost.localdomain.  How do I configure PostFix to go to smarthost and take a username and password?
0
arnoldCommented:
Edit /etc/postfix/main.cf
Look for myhostname=your hostname?yourdomain.com

This way when you restart postfix, this is the hostname it will use.  Make sure to use a valid domain for the hostname.
0
arnoldCommented:
You need to comment out the win32 related items out or it will continue to try accessing the smtp host rather than using the postfix locally.
0
hydraziAuthor Commented:
OK, but it doesn't seem to be using those settings.  I did like you said in php.ini, but I am thinking there needs to be settings for PostFix somewhere that need to be changed.  Right?
0
arnoldCommented:
I do not understand your last question.
1) to control the hostname that postfix uses, you have to change the myhostname= entry in /etc/postfix/main.cf and restart postfix.

2) making the changes in php.ini by commenting out the variables within the win32 settings and only leaving the sendmail_path=/usr/sbin/sendmail -oi -t
only.

within php you can pass the additional parameter of -fsender_email@yourdomain.com that will be passed/included when the mailing occurs.

what does not seem to be using those settings?

if you can post what you are trying to do in PHP, then the entries from /var/log/maillog that apply to your mailing attempt.
0
hydraziAuthor Commented:
OK, I was not aware that I needed to make changes to postfix.cf, but I figured that out by googling it.  Not sure how to turn on SMTP authetication because that is the last error at this time.....  I will google that too and update.
0
arnoldCommented:
I do not understand what you are looking for in postfix.cf or master.cf.

PHP will use mail() function and inject the message into your postfix queue.

Where do you need authentication?

Does postfix need to connect to your ISP mail server and authenticate?

to configure outgoing transport with authentication
you would look for transport within /etc/postfix/main.cf

which should point to /etc/postfix/transport
in this file there is a description of all the options.

to route all messages through your ISP mail servers you will add the following entry to the transport file
*     SMTP:ispmailserver:25

once saved run
postconf hash:/etc/postfix/transport
open/create /etc/postfix/password
ispmailserver                      username:password

save this.

run postconf hash:/etc/postfix/password
since you indicate you made changes based on google, presumably the addition you made deals with the /etc/postfix/password file in the outgoing connection section.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hydraziAuthor Commented:
Yes, I need to send all mail through my ISP SMTP server needing username and password.  

Thanks for your continued help[, learning a lot here!

I went into main.cf and there are many places that Transport is mentioned.  
Mailbox_transport
fallback_transport

I am unsure of the specifics of how to point it to a transport file correctly (I know it is just adding a line but does in need a path too?)
0
arnoldCommented:
The two you referenced are not the right ones.

There is a relayhost entry where you can set the reference to your ISP's mail server.


Search for postfix smtp client authentication

http://www.cyberciti.biz/faq/postfix-smtp-authentication-for-mail-servers/
0
hydraziAuthor Commented:
Wow, thanks for getting me through that.  Works better than ever!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.