-   Programming (
-   -   PHP Shell Script (with MySql) (

Tony Empire 09-20-2005 09:04 AM

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?

gakom 09-20-2005 10:59 AM

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.

All times are GMT -5. The time now is 06:14 AM.