0

Hello I am sending mail from php. I am fetching to address and cc address from database and storing them in one one variable. $to,$cc i need to use this in mailx command. Following query is hardcoded and its working.

 exec('echo "hey i am there" | mailx -S smtp=10.0.8.8:25 -r [email protected] -s "Alert" [email protected]');

Need to replace

 $message = hey i am there
 [email protected]
 $from [email protected] 
 $subject = Alert

exec('echo $message | mailx -S smtp=10.0.8.8:25 -r $from  -s $subject $to');

But the above thing is not working

4
  • Just change ' to " like exec("echo $message | mailx -S smtp=10.0.8.8:25 -r $from -s $subject $to"); Commented May 17, 2016 at 11:46
  • use double quote instead of single quote Commented May 17, 2016 at 11:47
  • There's two good answers now, please accept one of them so other people can benefit from them! Commented May 17, 2016 at 12:02
  • @Loek i am getting error as below smtp-server: 501 5.1.3 Invalid address Commented May 17, 2016 at 12:16

2 Answers 2

4

Just change ' to " like

exec("echo $message | mailx -S smtp=10.0.8.8:25 -r $from  -s $subject $to");
Sign up to request clarification or add additional context in comments.

1 Comment

I'd recommend adding some calls to escapeshellarg as well
2

You should concatenate your strings.

exec('echo ' . $message . ' | mailx -S smtp=10.0.8.8:25 -r ' . $from . ' -s ' . $subject . ' ' . $to);

1 Comment

You missed the $message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.