To my surprise it did work on my computer. I would think that in this line:
Code:
system("echo '$mailmsg' | mail -s 'Hi' $email ");
PHP would not be able to substitute the $mailmsg variable because of the quoting. But it did work...
Anyways, I would have construct a string containing the command first, and then execute it with system(). This also gives you an opportunity to put an "echo $command" in between, to check that what actually gets executed.
Code:
$name = "Mr. X";
$email = "heiko@localhost";
$mailmsg = "Hey, how are you doing $name";
$command = 'echo "'. $mailmsg .'" | mail -s "Hi" '. $email;
echo "Debug: ". $command ."<br />\n";
system($command);
For larger or more complex mail mesages I'd probably use popen() (check the manual).