views:

29

answers:

1

I use mstmp to send mail from various smtp account. Using PHP's mail command it sucessfull sends mail from mstmp using the default account.

However, I want it to let me specify which smtp account to send from. Using mstmp you do that with the following command: msmtp --account=svh where svh is the smtp account you name. More on msmtp can be found here: msmtp sourceforce

So what are my options, is there a modified mail command that will let me use msmtp using the --account parameter ? Should i just run a shell command with root privilege (don't want to do that).

How would you tackle this?

+2  A: 

Looks like msmtp has a way where you can define a config to be system wide so www-data can actually run the command and have the emails I need. Love msmtp.

Edit: Here is my quick and dirty function to do what I wanted, incase someone needs this later. I highly suggest you do more error-checking.

function msmtp($To, $Subject, $Body, $Headers, $Account) {
    $Email = "To: $To\nSubject: $Subject\n$Headers\n\n$Body\n";
    exec("echo '$Email' | msmtp --account=$Account $To");
}

Its very similar to the PHP mail() function so you would send an email as stevejobs to bill gates as follows, using the msmtp account "apple":

msmtp("[email protected]", "Hey, please read this", "You are too rich, give me all your money", "From: [email protected]", "apple")

BHare