tanveer Posted April 6, 2009 Share Posted April 6, 2009 Hi all, I have done a php page which will send a mail to user using mail function and its working. Now there is a tool named nail which can also send mail without using the sendmail so my code looks like this as a sample <?php $message="Hi test"; system('cat $message | /usr/local/bin/nail -r [email protected] -s "Test Mail with Nail" [email protected]') ?> It sends the mail ok but the body is blank. It doesn't print the message in the mail. Any idea how to made that work as I am not willing to use sendmail and mail function for this. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/ Share on other sites More sharing options...
jonsjava Posted April 6, 2009 Share Posted April 6, 2009 instead of using this <?php $message="Hi test"; system('cat $message | /usr/local/bin/nail -r [email protected] -s "Test Mail with Nail" [email protected]') ?> use this: <?php $message = "Hi test"; system('echo "'.$message.'" | /usr/local/bin/nail -r [email protected] -s "test Mail with Nail" [email protected]'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-802415 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 Variables won't interpolate in single quotes. You either have to break out of single quotes (like jonsjava did) or, use double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-802487 Share on other sites More sharing options...
jonsjava Posted April 6, 2009 Share Posted April 6, 2009 also, cat is the wrong method. Use echo (as I stated above) Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-802536 Share on other sites More sharing options...
tanveer Posted April 7, 2009 Author Share Posted April 7, 2009 Great. Thanks a lot. One problem solved. But the issue is, I am actually sending a mail with lots of html tagging in it and mail function does interpret that well in users mailbox. But when sending mail with nail then users get this <html><body>Hi test</body></html> in their mail body. But if use mail() function then only Hi Test comes in mail body without the html tags. How to accomplish that with nail? Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-803128 Share on other sites More sharing options...
ghostdog74 Posted April 7, 2009 Share Posted April 7, 2009 Now there is a tool named nail which can also send mail without using the sendmail so my code looks like this as a sample <?php $message="Hi test"; system('cat $message | /usr/local/bin/nail -r [email protected] -s "Test Mail with Nail" [email protected]') ?> i would advise against using external shell tools like that as it makes your code not portable. whenever and wherever you can, always try to use PHP's mail methods/classes. Here it has example of how to send html email. I am also sure that if you search hard enough you can find lots of examples on the net. Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-803175 Share on other sites More sharing options...
tanveer Posted April 7, 2009 Author Share Posted April 7, 2009 My intention was not to use the service sendmail for sending mails in my linux server. I was willing to send it to my already setup external mail server and that will do the rest. In 'nail' you can define your external server and it will just send the mail to that server. But for mail() function to work I have keep sendmail service started which I wasn't willing to do. And currently I am doing this with mail() function so I have the idea how to send via mail(). Is there any way I can keep sendmail off and still use the mail() function to send mail to my external mail server for action. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-803193 Share on other sites More sharing options...
trq Posted April 7, 2009 Share Posted April 7, 2009 Is there any way I can keep sendmail off and still use the mail() function to send mail to my external mail server for action. Yes. nail is meant to emulate sendmail. You need to move sendmail, and link nail into its place. eg; cd /usr/bin mv sendmail sendmail.bkp ln -s nail sendmail PHP would then use /usr/bin/sendmail (which is actually a link to /usr/bin/nail) to send your mail. Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-803236 Share on other sites More sharing options...
ghostdog74 Posted April 7, 2009 Share Posted April 7, 2009 Is there any way I can keep sendmail off and still use the mail() function to send mail to my external mail server for action. you do not need to start a mail service if all you are doing is sending out mails. Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-803242 Share on other sites More sharing options...
trq Posted April 7, 2009 Share Posted April 7, 2009 Is there any way I can keep sendmail off and still use the mail() function to send mail to my external mail server for action. you do not need to start a mail service if all you are doing is sending out mails. No, but you need access to one. Quote Link to comment https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/#findComment-803245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.