LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sending E-Mail From a Different Server Using PHP (https://www.linuxquestions.org/questions/programming-9/sending-e-mail-from-a-different-server-using-php-665336/)

stevec 08-25-2008 04:34 PM

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.

TB0ne 08-25-2008 04:48 PM

Quote:

Originally Posted by stevec (Post 3259487)
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.

Just configure your system to use the other mail server as a relay-host, then use system() or exec() to call a simple script, that uses mailx to fling out a message. I'd be surprised if you don't already have sendmail or postfix on your system.....

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.

stevec 08-25-2008 05:17 PM

Quote:

Originally Posted by TB0ne (Post 3259496)
Just configure your system to use the other mail server as a relay-host, then use system() or exec() to call a simple script, that uses mailx to fling out a message. I'd be surprised if you don't already have sendmail or postfix on your system.....

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.

Set the other server as a relay-host? Is that something that requires an MTA, or can I set it in my php.ini? The server this script is running on is an Ubuntu server I set up myself. No sendmail or postfix because I was told it would be in my best interest to make sure all mail was handled by the mail server when I inherited the job.

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.

Thank you.

Mr. C. 08-25-2008 09:18 PM

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.

TB0ne 08-26-2008 09:01 AM

Quote:

Originally Posted by stevec (Post 3259520)
Set the other server as a relay-host? Is that something that requires an MTA, or can I set it in my php.ini? The server this script is running on is an Ubuntu server I set up myself. No sendmail or postfix because I was told it would be in my best interest to make sure all mail was handled by the mail server when I inherited the job.

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.

Thank you.

No, you set the relay host in the sendmail/postfix configuration. All that does is tell the system that any emails it wants to send out, to relay them to another server, that does that. Since you say you've already got a mail server up and running in your environment, you're just using what you've already got.

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.

stevec 08-27-2008 03:46 PM

Solution
 
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.

gnuzilla 08-02-2011 12:53 PM

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.

BTW...
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.

----------EDITED--------------

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)

MSMTP !!!!!
http://msmtp.sourceforge.net/

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.
https://wiki.archlinux.org/index.php...HP_using_msmtp

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 12:50 PM.