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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-28-2013, 03:17 AM
|
#1
|
|
Member
Registered: Jan 2004
Posts: 357
Rep:
|
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");
?>
|
|
|
|
|
02-28-2013, 08:55 AM
|
#2
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078
|
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.
|
|
|
|
02-28-2013, 09:34 AM
|
#3
|
|
Member
Registered: Aug 2008
Distribution: Slackware
Posts: 195
Rep:
|
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.
|
|
|
|
02-28-2013, 10:26 AM
|
#4
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078
|
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.
|
02-28-2013, 11:28 AM
|
#5
|
|
Member
Registered: Jan 2004
Posts: 357
Original Poster
Rep:
|
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.
|
|
|
|
03-01-2013, 01:47 AM
|
#6
|
|
Member
Registered: Jan 2004
Posts: 357
Original Poster
Rep:
|
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)';
|
|
|
|
|
03-01-2013, 02:19 AM
|
#7
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078
|
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
|
|
|
|
03-01-2013, 08:21 PM
|
#8
|
|
Member
Registered: Jan 2004
Posts: 357
Original Poster
Rep:
|
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)
|
|
|
|
|
03-01-2013, 11:10 PM
|
#9
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,078
|
You should read the documentation to find out the expected date format, and implement that with PHP's date function.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:01 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|