Sending E-Mail From a Different Server Using PHP
I'm writing a PHP script to wrap execution of another program. Upon completion of the program I want PHP to send an e-mail to the user that the job is complete.
The server that this PHP script is running on does not have a MTA installed on it and I don't really want to install one just for this, especially since we have another server with sendmail already configured. The mail server *does* have PHP installed as well.
I'm not familiar with sendmail nor MTAs in general. The only thing I can think to do is call a PHP script on the mail server itself through SSH, but surely there's a better way to do it.
I get the impression there should be some way to pass the mail with PEAR::Mail, but I'm not sure how to figure out what parameters to pass to the mail server. Can I use PEAR::Net_SMTP somehow?
Thank you for any help.
If this is a once-in-a-while thing, and the users are limited, it'll save lots of coding. You may need to do something more 'industrial strength', if you have more users, though.
There's no reason for this server to do any e-mailing. The only 'user' are scripts that sometimes need to mail people when a job is complete, or whatever.
I'm all for saving coding.
I'm gonna look through my php.ini to see if I can find a way to set a relay-host in there.
The php mail() command uses the sendmail binary. If you don't have an MTA installed, you will not have a sendmail binary.
If you don't want to install an MTA that includes the sendmail binary, you can use any PHP SMTP library and manage the mail object and connection to a valid mailserver yourself.
The PHP SMTP library that Mr. C. recommended would be a good way to go also...much cleaner than calling a shell-script, but would take a bit more effort.
Thanks to everyone for their help.
The server with the program running on it that needed to make the e-mail has no MTA. We have a physically separate mail server that handles all e-mail and that is the only machine running sendmail currently (that and the box I do my development on). From what I can tell from the advice here and what I've read to directly access mail from this program I would either have to install sendmail on the server running the program or configure sendmail on the mail server to allow mail-relaying.
I've come up with a work around. I'm going to create a simple and generic e-mail class in PHP to go on the mail server (which also has PHP and a web server), and then use cURL from the program in question to get the mail server to send the e-mail. I'll secure the script with .htaccess so that only the programs I specify will be able to use the mail script.
Thank you all for the help. I greatly appreciate it.
Thanks to everyone for help?
Thanks to everyone for help? for what?? Not actually listening to your question, frustrating you to the point of having to recreate a solution, which we could assume has been done before?
i know, i'm somewhat out of line... but is it surprising people don't want a whole MTA installed to do the job of mutt/mailx ?!?!?! A whole unnecessary MTA, the fact it can remain unconfigured further illustrates my point.
Setting up an MTA to relay to another MTA, is just that. Two MTA's instead of just one.
PHP really let the ball slip on this one, apparently not for windoze (from what i see in the php documents).
i don't even expect an answer at this point, so i prefer not to be informed of the many reasons why.
I found an answer, For anyone who is looking for answers in the sea of misinformation (entire internet, not specific to LQ.. i like LQ)
its a /usr/bin/sendmail compatible MUA, no running services. After the fact, I noticed some other post at LQ mentions it (unfortunately not how i was informed)
ArchWiki has a great tutorial on configuring PHP with mstmtp as the sendmail MUA option.
I know i'm a jerk, but i was frustrated. I hope this post helps people who hit this from Google.
|All times are GMT -5. The time now is 05:56 AM.|