Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm sending mail from my applications in PHP by using the mail() function. This function uses the local sendmail to do the work. But I would like to free the server from the burden of also being a mail server, and wanted to know if I can use the sendmail program in my other server. Or somehow make the local sendmail to relay to the other server to send the mail for it.
That is, is there a way to tell PHP, or sendmail, to use a given IP instead of local, to send mail?
Configuring sendmail is not so easy. Consider using postfix as drop-in replacement instead.
According to http://www.sitepoint.com/article/advanced-email-php, you can use the standard mail() function in PhP. Just use the SMTP option to specify the name of your SMTP server (ie the name of the computer where you have a running sendmail that accepts SMTP connections from the machine that runs PhP).
By default, sendmail is probably only listening to e-mails originating from the machine it runs on. So the "burden" of running the mail server (which is running on many systems this way) is not so high. Relaying and stuff is more troublesome. Remember also that other services, like cron for one, often rely on a running MUA like sendmail that listens to the SMTP port of the localhost interface.
Have you also taken a look at: http://phpmailer.sourceforge.net/
I haven't tried it, but it seems to promise what you need - specifying random SMTP servers to use for mailing).
Configuring sendmail is not so easy. Consider using postfix as drop-in replacement instead.
I don't know, I have been using sendmail for long now and can configure lots of things with it, so changing now would imply an effort and investment that would need some justification. Why do you say postfix is better than sendmail in this case?
Quote:
Originally Posted by timmeke
According to http://www.sitepoint.com/article/advanced-email-php, you can use the standard mail() function in PhP. Just use the SMTP option to specify the name of your SMTP server (ie the name of the computer where you have a running sendmail that accepts SMTP connections from the machine that runs PhP).
Yes, that article seems to imply that you can indicate the SMTP server in php.ini also for Linux servers, but I have tried it (commenting out the sendmail_path parameter) and it didn't change anything. It looks like sendmail must not be installed for this to work (I tried stopping sendmail, but that just delayed the sending until I started it up again).
Quote:
Originally Posted by timmeke
By default, sendmail is probably only listening to e-mails originating from the machine it runs on. So the "burden" of running the mail server (which is running on many systems this way) is not so high. Relaying and stuff is more troublesome. Remember also that other services, like cron for one, often rely on a running MUA like sendmail that listens to the SMTP port of the localhost interface.
You are right there, I will need sendmail for the cron processes, and maybe just sending mail is not so consuming. In fact, does anyone know if using a remote SMTP server to send an email requires less processing and memory than sending it from the local SMTP?
I don't know, I have been using sendmail for long now and can configure lots of things with it, so changing now would imply an effort and investment that would need some justification. Why do you say postfix is better than sendmail in this case?
I didn't know about your ample experience with sendmail. So forget about postfix. I prefer postfix over sendmail just because it's easier to configure.
Quote:
Originally Posted by czamora
Yes, that article seems to imply that you can indicate the SMTP server in php.ini also for Linux servers, but I have tried it (commenting out the sendmail_path parameter) and it didn't change anything. It looks like sendmail must not be installed for this to work (I tried stopping sendmail, but that just delayed the sending until I started it up again).
That's a sign that the mail gets spooled. You can use the sendmail binary (or /bin/mail) to add new mails to sendmail's queue. They'll stay in that queue until sendmail either delivers them or decides to give up trying. So, my guess is that you're still accessing your MUA somehow, even though the sendmail daemon was stopped. What you should do instead is open an SMTP connection on the remote machine (that's running sendmail) and use that to send out the mail. The SMTP protocol is fairly simple, so you could try to do that yourself, but I don't recommend it. Does the link to the sourceforge tool for sending out mails via PhP help?
Quote:
Originally Posted by czamora
You are right there, I will need sendmail for the cron processes, and maybe just sending mail is not so consuming. In fact, does anyone know if using a remote SMTP server to send an email requires less processing and memory than sending it from the local SMTP?
The sendmail daemon will sleep for most of the time (until you use it to send out a mail) and probably just checks its configuration and the mail spool from time to time. Sending out the mails themselves isn't very demanding on resources either, unless you add large attachments that consume network bandwidth.
So, in general, sendmail daemon shouldn't be a resource hog if you configure it properly and if it listens only to the SMTP port on the localhost interface (ie no relaying for other hosts). Sending mail via SMTP to a remote server uses probably less memory/cpu/resources (in fact, I do this on one of my machines via "nail"), but it won't make much difference, unless your machine is under very heavy load or sending out tons of mails.
What you should do instead is open an SMTP connection on the remote machine (that's running sendmail) and use that to send out the mail. The SMTP protocol is fairly simple, so you could try to do that yourself, but I don't recommend it. Does the link to the sourceforge tool for sending out mails via PhP help?
That php class looks interesting and I'll keep it in mind for other things, but I was hoping for a solution that didn't imply code changes.
Quote:
Originally Posted by timmeke
Sending mail via SMTP to a remote server uses probably less memory/cpu/resources (in fact, I do this on one of my machines via "nail"), but it won't make much difference, unless your machine is under very heavy load or sending out tons of mails.
Isn't "nail" a mail client? Do you use it to send mail programatically from your software?
nail is indeed a mail client, but you need a client to send out mail. Sendmail was originally an MUA, not a client, but the standalone sendmail application (not in daemon mode) can be used to send out mails too (like a client).
I use nail to send out reports of processing jobs (mostly scheduled via cron). The nail program is then called as part of the cron job and from scripts. nail is configured to use a different machine's postfix daemon to send out the mails. This 2nd machine is a mail server and it's contacted via SMTP directly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.