LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-25-2008, 04:34 PM   #1
stevec
LQ Newbie
 
Registered: Mar 2004
Location: Bloomington, IN
Posts: 21

Rep: Reputation: 15
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.

Last edited by stevec; 08-25-2008 at 04:36 PM.
 
Old 08-25-2008, 04:48 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,137

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by stevec View Post
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.
 
Old 08-25-2008, 05:17 PM   #3
stevec
LQ Newbie
 
Registered: Mar 2004
Location: Bloomington, IN
Posts: 21

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by TB0ne View Post
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.
 
Old 08-25-2008, 09:18 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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.
 
Old 08-26-2008, 09:01 AM   #5
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,137

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Quote:
Originally Posted by stevec View Post
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.
 
Old 08-27-2008, 03:46 PM   #6
stevec
LQ Newbie
 
Registered: Mar 2004
Location: Bloomington, IN
Posts: 21

Original Poster
Rep: Reputation: 15
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.
 
Old 08-02-2011, 12:53 PM   #7
gnuzilla
LQ Newbie
 
Registered: Apr 2006
Location: Chagrin Falls, OH
Distribution: Ubuntu / Debian
Posts: 17

Rep: Reputation: Disabled
Thumbs down 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.

Last edited by gnuzilla; 08-02-2011 at 02:00 PM.
 
  


Reply

Tags
mail, pear, php, sendmail


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP mail() sending as apache@ipaddress DukeLeto Linux - Software 1 04-13-2007 10:24 PM
Sending mail with PHP on linux machine through exchange on Windows server 2003 TVScoundrel Linux - Newbie 1 06-18-2004 01:22 PM
Sending mail with PHP on linux machine through exchange on Windows server 2003 TVScoundrel Linux - Networking 2 06-18-2004 12:02 PM
Sending mail with PHP and sendmail. davemar Linux - General 10 06-11-2004 04:48 PM
Form not sending mail using includes... PHP cadkins Programming 3 04-27-2004 06:38 PM


All times are GMT -5. The time now is 08:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration