LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
Search this Thread
Old 09-20-2005, 09:04 AM   #1
Tony Empire
LQ Newbie
 
Registered: Nov 2004
Location: Long Island, NY
Distribution: Redhat 9
Posts: 17

Rep: Reputation: 0
PHP Shell Script (with MySql)


Hello all:

Here is my code

Code:
#!/usr/local/bin/php -q
<?
include ("/home/someuser/somedirectory/databaseinfo.inc.php"); // stores db username, passwords, connection, etc
$query="SELECT * FROM table1 WHERE status = 'new' ORDER BY id DESC"; // selects only records flagged as new
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

echo "Database Output\n\n";

$i=0;
while ($i < $num)
{
$name=mysql_result($result, $i, "name");
$email=mysql_result($result, $i, "email");
$user=mysql_result($result, $i, "type");
$company=mysql_result($result, $i, "company");
$comment=mysql_result($result, $i, "comment");
$datetime=mysql_result($result, $i, "datetime");

echo "Name: ".$name."\n".
     "Email: ".$email."\n".
     "User Type: ".$user."\n".
     "Company: ".$company."\n".
     "Comment: ".$comment."\n".
     "Date: ".$datetime."\n";

$to = "some@emailaddress.com";
$subject = "Contact from ".$email;
$body= "Name: ".$name."\n".
       "Email: ".$email."\n".
       "User Type: ".$user."\n".
       "Company: ".$company."\n".
       "Comment: ".$comment."\n".
       "Date: ".$datetime."\n>";

mail($to, $subject, $body);

echo "Message sent on ".date("r")."\n\n";

$i++;
}
?>

Almost everything runs properly, but i get error
Code:
sh: line 1: -t: command not found
which refers to the line of code
Code:
mail($to, $subject, $body);
and of course, the email does not go out.


What is the problem and how can I correct it?
 
Old 09-20-2005, 10:59 AM   #2
gakom
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Rep: Reputation: 0
Is sendmail listed in your PATH ? PHP will first look for sendmail in your PATH, and then in the following: /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary.


I used the following for:

$didgo =mail($to, $subject, $message, $headers);

#error checking for email #

if (!$didgo){
echo "EMail could not be sent ";

}

This way I get immediate feed back if the email can not be sent.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a shell script from php? jharper101 Programming 2 02-15-2005 01:51 AM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 12:51 PM
MySQL in a shell script?! zaubara Programming 2 05-31-2004 06:27 PM
converting shell script to php script ? ibro Linux - General 6 05-24-2004 06:19 AM
How get a mysql shell response in a script. philipina Programming 3 03-16-2004 12:51 PM


All times are GMT -5. The time now is 10:53 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 Google+: linuxquestions
Open Source Consulting | Domain Registration