Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/152783-run-linux-shell-command/
Share on other sites

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]');
?>

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.

 

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.

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.

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.