Brett Cohen
Brett Cohen

Reputation: 161

Unix Mail from PHP

So I would like to be able to call the unix mail function form a PHP script. Yes, I know PHP has a built in mail function itself, but I am having issues with the PHP config on my intranet server and have been trying very hard to resolve with no such luck. I figured it would be easier to just invoke the Unix mail function (since I know it works with other scripts) from PHP instead of trying to re-configure the PHP install, which could end up messing things up for other sites. Could someone explain how to accomplish this as well as how I can set up an email template to be sent out in the email? Thanks in advance !!

Brett

Upvotes: 0

Views: 1615

Answers (2)

C. Ramseyer
C. Ramseyer

Reputation: 2382

Try something like system('/usr/bin/mailx -s "Your Subject" [email protected] < /tmp/mailfile.txt')

Be careful if the input is accepted from the user, read these first:

All in all, it would be much safer and portable to use the mail functions available in PHP. Also, your provier may disable the system and similar functions (by using safe_mode).

Upvotes: 0

Alice Wonder
Alice Wonder

Reputation: 916

Calling unix commands directly requires that your php install be allowed to execute shell commands which is dangerous and really should only be done in cases where there is not a suitable pure php wrapper. There is a suitable wrapper in php. What problems have you been having with it?

To answer your question, look at the exec() function. Unless php is configured to disallow it, that is how you call external commands from within php. I still recommend against it.

For generating and sending e-mail from a php web application, I find that the phpMailer is an excellent easy to use php class.

Upvotes: 1

Related Questions