LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 09-23-2004, 04:05 AM   #1
evilchild
Member
 
Registered: Sep 2003
Location: 127.0.0.1
Distribution: *bsd, solaris, gentoo
Posts: 86

Rep: Reputation: 15
using 'echo' in a system statment in php


I'm trying to send an email from a php script, using a system statement that executes 'echo' and ports the output of the echo command into 'mail' command like so
Code:
$name = "Mr. X";
$email = "me@my.domain"; 
$mailmsg = "Hey, how are you doing $name";
system("echo '$mailmsg'  | mail -s 'Hi' $email ");
but the problem here is when i use echo to echo the contents of the variable $mailmsg, it doesn't seem to work, but the mail part of the statement works, so this script results in sending a empty null message to the email contained in the $email variable. Is there some thing i'm missing here.
 
Old 09-23-2004, 05:03 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
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).

Last edited by Hko; 09-23-2004 at 05:04 AM.
 
Old 09-23-2004, 08:02 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 241Reputation: 241Reputation: 241
why not use the integred mail() function as it seems you use sendmail
PHP Code:
$name "Mr. X";
$email "heiko@localhost"
$mailmsg "Hey, how are you doing $name";
mail($email"Hi"$mailmsg); 
 
Old 09-23-2004, 02:27 PM   #4
evilchild
Member
 
Registered: Sep 2003
Location: 127.0.0.1
Distribution: *bsd, solaris, gentoo
Posts: 86

Original Poster
Rep: Reputation: 15
thanks, that works. I never heard of the mail() function in php, we're always learning something new.
 
  


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 does not work in php code suchi_s Programming 3 10-21-2004 03:39 AM
Kphone echo (echo echo) scabies Linux - Software 0 10-18-2004 02:59 PM
so much errors (if statment ) huno Programming 4 07-20-2004 10:18 AM
PHP If statment agallant Programming 3 07-04-2004 09:02 AM
not able to run mysql statment Robin01 Linux - General 1 03-19-2004 07:03 PM


All times are GMT -5. The time now is 05:43 AM.

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