PHP script to use mail(x) for sending email using bash

Hello :)

On my linode I want to use Google's smtp servers to send some emails. I have the mailx program installed and this works great from bash.

# echo "This is a test email" | mail -v -s "Test email" someone@somewhere.com

All I need is to be able to provide the body, subject and to address from a PHP script and forward it to bash (anyway to do it inside PHP?) so it can send it away. I just need to send emails.. and can't get sendmail package working.

I am not much of a programmer so any help is very appreciated.. I was thinking of something along the lines.

Any chance something like that can work? Or if the syntax of the "echo" command inside exec is even correct. Thanks for any help/pointers. :)

2 Replies

You probably shouldn't use exec like that, but anyway.

First google result:

http://email.about.com/od/emailprogramm … g_Mail.htm">http://email.about.com/od/emailprogrammingtips/qt/ConfigurePHPtoUseaRemoteSMTPServerforSendingMail.htm

that google result is more geared towards php running in a windows environment. I know php is the same, but I tried using what they are saying and got nowhere.

Now I am looking at using PHPMailer.. still no luck tho. :(

Edit: Just to clarify I don't have any mail servers (sendmail, postfix, exim etc.) running.. just trying to send mail with php (have pear extension). Is this even doable? :? I have seen a ton of posts on the net regarding this but really nothing has worked for me.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct