LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP Shell Script (with MySql) (https://www.linuxquestions.org/questions/programming-9/php-shell-script-with-mysql-365196/)

Tony Empire 09-20-2005 08:04 AM

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?

gakom 09-20-2005 09: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 09:45 PM.