LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-28-2013, 03:17 AM   #1
shams
Member
 
Registered: Jan 2004
Posts: 357

Rep: Reputation: 30
echo command didn't pipe the output to the msmtp?


In this php code, echo command didn't pipe the output to the msmtp:
Quote:
<?php
$from = $_POST['from'];
$To = $_POST['To'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$account = $_POST['account'];

ob_start();
echo "Subject:".$subject."\n To:".$To."\n From:". $from."\n\n".$message;
$str = ob_get_contents();
ob_end_clean();

exec("echo $str | msmtp --account=$account -f $from $To");
?>
 
Old 02-28-2013, 08:55 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078

Rep: Reputation: 317Reputation: 317Reputation: 317Reputation: 317
How do you know it? How did you check the return codes / error-messages? Did you test it with redirection to file, eg:
Code:
exec ("echo $str >testfile");
And do you know how dangerous it is? what if $_POST['from']=`rm -rf ~`

Last edited by NevemTeve; 02-28-2013 at 08:57 AM.
 
Old 02-28-2013, 09:34 AM   #3
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 195

Rep: Reputation: 56
You are doing it wrong since you're inviting everyone to destroy your machine by simple HTTP request (as per NevemTeve's comment). Use popen instead and write directly to the pipe. No output buffering needed.
 
Old 02-28-2013, 10:26 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078

Rep: Reputation: 317Reputation: 317Reputation: 317Reputation: 317
Note: If you want it this way (not recommended), then it would be something like this:

Code:
<?php
    $from = $_POST['from'];
    $To = $_POST['To'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    $account = $_POST['account'];

    $str= sprintf ("Subject: %s\nTo:%s\nFrom: %s\n\n%s",
        $subject, $To, $from, $message);
    putenv ("str=".$str);
    putenv ("from=".$from);
    putenv ("to=".$To);
    putenv ("account=".$account);

    exec ('echo "$str" | msmtp --account="$account" -f "$from" "$To"');
?>
 
1 members found this post helpful.
Old 02-28-2013, 11:28 AM   #5
shams
Member
 
Registered: Jan 2004
Posts: 357

Original Poster
Rep: Reputation: 30
Thanks for replies and suggestions the code of NevemTeve worked perfect, i will also try the popen but i need to read a lot because i don't have enough knowlegde about coding, i only copy the codes and make the new one for my use.
 
Old 03-01-2013, 01:47 AM   #6
shams
Member
 
Registered: Jan 2004
Posts: 357

Original Poster
Rep: Reputation: 30
I added the $Date variable to the above code but print the wrong date in the email headers, the system date is correct:
Quote:
$Date='$(date +%Y-%m-%d-%H:%M:%S %UT)';
 
Old 03-01-2013, 02:19 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078

Rep: Reputation: 317Reputation: 317Reputation: 317Reputation: 317
It doesn't seem to be valid PHP code...
Code:
    $tm = time ();
    $date = date ('Y-m-d-H:i:s', $tm);
    printf ("now is %s\n", $date);
http://www.php.net/manual/en/function.date.php
 
Old 03-01-2013, 08:21 PM   #8
shams
Member
 
Registered: Jan 2004
Posts: 357

Original Poster
Rep: Reputation: 30
Thanks for the reply, the above date code work fine alone but whein i added to the mail header still print the wrong time:
Quote:
<?php
$From = $_POST['From'];
$To = $_POST['To'];
$Subject = $_POST['Subject'];
$Body = $_POST['Body'];
$account = $_POST['account'];
$tm = time ();
$Date = date ('Y-m-d-H:i:s', $tm);

$str= sprintf ("Subject: %s\nTo:%s\nFrom:%s\nDate: %s\n\n%s",
$Subject, $To, $From, $Date, $Body);
putenv ("str=".$str);
putenv ("From=".$From);
putenv ("To=".$To);
putenv ("account=".$account);
putenv ("Date=.$Date");

exec ('echo "$str" | msmtp --account="$account" -f "$From" "$To"');
echo '<b>Message Sent, thank you</b>';

?>
This is the time was print in the email header:
Quote:
Date: Thu, 01 Jan 1970 04:30:00 +0430 (Unknown)
 
Old 03-01-2013, 11:10 PM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078

Rep: Reputation: 317Reputation: 317Reputation: 317Reputation: 317
You should read the documentation to find out the expected date format, and implement that with PHP's date function.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
echo two command output in the same line chuikingman Linux - Software 8 03-31-2011 06:20 PM
How to pipe output to another command parameter? FireRaven Linux - Newbie 2 07-20-2009 07:44 AM
How can I pipe output of a command into arguments of a script HGeneAnthony Linux - General 3 12-26-2007 06:24 AM
Pipe output of command to php !!! ALInux Programming 7 12-30-2006 12:36 PM
how to pipe and parse output of a command learnfast Linux - Newbie 2 06-15-2005 04:55 AM


All times are GMT -5. The time now is 08:01 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration