Jump to content

php retrieving data from mysql table and sending it in e-mail form


kahodges

Recommended Posts

Can anyone tell me what I'm doing wrong? Thanks in advance. Here's the code:

#!/usr/bin/php -q -c /etc/php.ini
<?
$dbhost = "localhost"; 
$dbuser = "username";
$dbpass = "password";
$dbname = "database";
mysql_connect($dbhost,$dbuser,$dbpass);
@mysql_select_db($dbname) or die("Unable to select database");
return $conn;
$query = "SELECT id, vehicle, last_date, due_date FROM inspection WHERE DATE_ADD(CURDATE(),INTERVAL 30 DAY) = due_date;";
$row = mysql_query($query) or die(mysql_error());
$sendto = "Me <[email protected]>";
$sendfrom = "System Backup <[email protected]>";
$sendsubject = "Maintenance Reminder";
$bodyofemail = $row['vehicle']." ".$row['last_date']." ".$row['due_date'];

// Mail the file

    include('Mail.php');
    include('Mail/mime.php');

$message = new Mail_mime();
$text = "$bodyofemail";
$message->setTXTBody($text);
$message->AddAttachment($backupfile);
    	$body = $message->get();
        $extraheaders = array("From"=>"$sendfrom", "Subject"=>"$sendsubject");
        $headers = $message->headers($extraheaders);
    $mail = Mail::factory("mail");
    $mail->send("$sendto", $headers, $body);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.