Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  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

#!/usr/local/bin/php -q
include ("/home/someuser/somedirectory/"); // stores db username, passwords, connection, etc
$query="SELECT * FROM table1 WHERE status = 'new' ORDER BY id DESC"; // selects only records flagged as new

echo "Database Output\n\n";

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 = "";
$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";


Almost everything runs properly, but i get error
sh: line 1: -t: command not found
which refers to the line of 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
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.


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:37 AM.

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