Jump to content

PHP sending e-mail problem


kahodges

Recommended Posts

Here is the code I have so far:

<?php
include('database.inc.php'); // Our database connectivity file

?>
<?php

$reminder_date = 't1.reminder_date';
$email = 'lp_reminder_email';
$reminder_name = 't1.reminder_name';
$reminder_details = 't1.reminder_desc';


$result = mysql_query($sql) or die(mysql_error());

$sql = "SELECT t1.`reminder_id` , t1.`reminder_name` , t1.`reminder_desc` , t1.`reminder_date` , t1.`reminder_email` , lp4.`email` AS `lp_reminder_email` 
FROM `reminder_events` AS t1
LEFT OUTER JOIN `authorize` AS lp4 ON ( t1.`reminder_email` = lp4.`email` ) 
WHERE reminder_date <= NOW()
ORDER BY `reminder_date` ASC";
$result = 'mysql_num_rows';


while( $row = mysql_fetch_array( $result ) )

if( !empty( $nr ) )
?>
<?php
$to = $row[$email];
$from = $row[$email];
$headers = $from;
$subject = $row[$reminder_name];
$body = $row[$reminder_details];


{
$send = @mail($to, $subject, $body, $headers);
}

?>

 

The sql query when run through phpMyAdmin returns a result. When I open this in the browser, it says "Query is empty". Anyone want to help a newb out and show me what I'm doing wrong? I'd like for it to pull the data out of these fields and send it via e-mail. What would be even better is if I could get it to do this the day before the `reminder_date`. I can set it up so cron runs the script, I just need to get the script to work first.

 

Thanks in advance for your help.

Link to comment
Share on other sites

O.K., I enabled error reporting, and now it's not throwing any errors. However, it does not seem to be sending out the e-mail. Here is what I have now:

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
include('database.inc.php'); // Our database connectivity file

?>
<?php

$reminder_date = 't1.`reminder_date`';
$email = 'lp4.`email`';
$reminder_name = 't1.`reminder_name`';
$reminder_details = 't1.`reminder_desc`';


$sql = "SELECT t1.`reminder_id` , t1.`reminder_name` , t1.`reminder_desc` , t1.`reminder_date` , t1.`reminder_email` , lp4.`email` AS `lp_reminder_email`
FROM `reminder_events` AS t1
LEFT OUTER JOIN `authorize` AS lp4 ON ( t1.`reminder_email` = lp4.`email` ) 
WHERE reminder_date <= NOW( )
ORDER BY `reminder_date` ASC";

$result = mysql_query($sql) or die(mysql_error());

while( $row = mysql_fetch_array( $result ) )
?>
<?php
$to = $row[$email];
$from = $row[$email];
$headers = $from;
$subject = $row[$reminder_name];
$body = $row[$reminder_details];


{
$send = @mail($to, $subject, $body, $headers);
}

?>

Link to comment
Share on other sites

O.K., got it working like I want. Have a cron job set up, and now my reminder script is spitting out reminder e-mails. In case this will help anyone, here it is:

 

<?php
    include('database.inc.php'); // Our database connectivity file 


$sql = <<<EOL
SELECT t1.reminder_id AS reminder_id, t1.reminder_name AS reminder_name,
    t1.reminder_desc AS reminder_desc, t1.reminder_date AS reminder_date, 
    t1.reminder_email AS reminder_email, lp4.email AS lp_reminder_email 
FROM reminder_events AS t1 
LEFT OUTER JOIN authorize AS lp4 ON ( t1.reminder_email = lp4.email ) 
WHERE DAY(reminder_date) = DAY(DATE_ADD(CURDATE(),INTERVAL 1 DAY)) ORDER BY reminder_date ASC LIMIT 0 , 900000000000000000;
EOL;

$result = mysql_query($sql) or die(mysql_error());

while( $row = mysql_fetch_array($result)) {
    $to = $row["reminder_email"];
    $from = "reminder@mydomain.com";
    $headers = "From:$from";
    $headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
    $subject = $row["reminder_name"];
    $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
    $body = $row["reminder_desc"];

    mail($to, $subject, $body, $headers);

}
{
  mysql_query("DELETE FROM reminder_events WHERE DAY(reminder_date) = DAY(DATE_ADD(CURDATE(),INTERVAL 1 DAY))");
}

?>

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.