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 <me@mydomain.com>";
$sendfrom = "System Backup <admin@mydomain.com>";
$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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.