hydrazi
asked on
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!
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!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
OK, going to look around and get this closed up today. Sorry for the delay
ASKER
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?
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.
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.
ASKER
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. :)
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. :)
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?
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?
ASKER
Yes, smtp require authentication.
I will install postfix. At this point, it can't hurt.
I can change that hostname back to localhost.
I will install postfix. At this point, it can't hurt.
I can change that hostname back to localhost.
Do not change the hostname. Just trying to see what your hostname is.
ASKER
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.
I left with WIN32 items in there, but put the sendmail -oi -t as you specified.
ASKER
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?
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.
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.
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.
ASKER
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?
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/se ndmail -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.
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/se
only.
within php you can pass the additional parameter of -fsender_email@yourdomain.
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.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?)
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?)
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/
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/
ASKER
Wow, thanks for getting me through that. Works better than ever!
ASKER
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. :)