Cita:
Iniciado por mortiprogramador Saludo
Pues el tema de la base de datos se puede revisar como lo indica rbczgz
¿En cuanto al mail, que respuesta se obtiene de la función mail
al intentar hacer el envío?
Basta con un
Con respecto al EMAIL nose de donde optiene la funcion supongo internamente del sql ni idea.
me imagino que hay que ordenar todo o usar el cron etc. suponia que era corregir el error y funcionaba
como seria la solucion al codigo, quiza revisando el post donde viene la fuente comprenderas mejor el
problema, ya que usted conoce de programacion, espero me pueda ayudar
Fuente del codigo
Codigo "reminder_add.php"
Código PHP:
<?php
include('database.inc.php'); // Our database connectivity file
// Values you need set
$number_of_days_before = 1;
$email = "[email protected]"; // Aqui el email
$reminder_details = "";
$todays_date = date( "Ymd" );
$year = substr($todays_date, 0, 4);
$month = substr($todays_date, 4, 2);
$date = substr($todays_date, 6, 2);
$trigger_date = date("Ymd", mktime (0,0,0,$month,$date-$number_of_days_before,$year));
$result = mysql_query( "SELECT * FROM reminder_events WHERE reminder_date <= $trigger_date ORDER BY reminder_date ASC" );
$nr = mysql_num_rows( $result );
while( $row = mysql_fetch_array( $result ) )
{
$year = substr($row["reminder_date"], 0, 4);
$month = substr($row["reminder_date"], 4, 2);
$date = substr($row["reminder_date"], 6, 2);
$reminder_date = date("M j, Y", mktime (0,0,0,$month,$date,$year));
$reminder_details .= "Event: ".$row["reminder_name"]."\n";
$reminder_details .= "Date: ".$reminder_date."\n";
$reminder_details .= $row["reminder_desc"]."\n\n";
}
mysql_free_result( $result );
if( !empty( $nr ) )
{
// Send out Reminder mail
$mailheader = "From: Reminder System <$email>\nX-Mailer: Reminder\nContent-Type: text/plain";
mail("$email","Reminder","$reminder_details","$mailheader");
// Delete the sent reminders
mysql_query("DELETE FROM reminder_events WHERE reminder_date <= $trigger_date" );
}
?>
Codigo Original que hace el insert "reminder_setup.php"
Código PHP:
<?php
include('database.inc.php'); // Our database connectivity file
if($_POST['step'] != '1')
{
?>
<html>
<head><title>Add Reminders</title></head>
<body>
<form name="setup_reminder" action="reminder_setup.php" method="post">
<table border='0' align='center'><tr><td>Event:</td><td>
<input name="reminder_name" type="text" maxlength="255" />
</td></tr><tr><td>Description</td><td>
<textarea name="reminder_desc" rows="5" /></textarea>
</td></tr>
<tr><td>Trigger Date</td><td>
<select name="reminder_year">
<?php
$current_year = date("Y");
for($counter=$current_year;$counter<=$current_year+2;$counter++)
{
echo("\n<option>$counter</option>");
}
?>
</select>
<select name="reminder_month">
<?php
for($counter=1;$counter<=12;$counter++)
{
if($counter < 10)
$prefix = "0";
else
$prefix = "";
echo("\n<option>$prefix$counter</option>");
}
?>
</select>
<select name="reminder_date">
<?php
for($counter=1;$counter<=31;$counter++)
{
if($counter < 10)
$prefix = "";
echo("\n<option>$prefix$counter</option>");
}
?>
</select></td></tr><tr><td> </td><td>
<input name="step" type="hidden" value="1" />
<input name="submit" type="submit" value="add" />
</td></tr></table>
</form>
</body>
</html>
<?php
}
else
{
$error_list = "";
$todays_date = date( "Ymd" );
$reminder_date = $_POST['reminder_year'].$_POST['reminder_month'].$_POST['reminder_date'];
if( empty($_POST['reminder_name']) )
$error_list .= "No Reminder Name<br />";
if( !checkdate( $_POST['reminder_month'], $_POST['reminder_date'], $_POST['reminder_year'] ))
$error_list .= "Reminder Date is invalid<br />";
else if( $reminder_date <= $todays_date )
$error_list .= "Reminder Date is not a future date<br />";
if( empty( $error_list ) )
{
// No error let's add the entry
mysql_query( "INSERT INTO reminder_events(`reminder_name`, `reminder_desc`, `reminder_date`) VALUES('".addslashes($_POST['reminder_name'])."', '".addslashes($_POST['reminder_desc'])."', '".addslashes($reminder_date)."')" );
// Let's go to the Reminder List page
Header("Refresh: 1;url=reminder_list.php");
echo <<< _HTML_END_
Reminder Added, redirecting ...
_HTML_END_;
}
else
{
// Error occurred let's notify it
echo( $error_list );
}
}
?>
Modificado y el mensaje de "Reminder Date is invalid" "reminder_setup.php"
Código PHP:
<?php
include('database.inc.php'); // Our database connectivity file
if($_POST['step'] != '1')
{
?>
<html>
<head><title>Add Reminders</title></head>
<body>
<form name="setup_reminder" action="reminder_setup.php" method="post">
<table border='0' align='center'><tr><td>Event:</td><td>
<input name="reminder_name" type="text" maxlength="255" />
</td></tr><tr><td>Description</td><td>
<textarea name="reminder_desc" rows="5" /></textarea>
</td></tr><tr> <td>Date</td><td>
<input name="reminder_date" type="text" maxlength="255" />
(Y-m-d)</td></tr><tr><td> </td><td>
<input name="step" type="hidden" value="1" />
<input name="submit" type="submit" value="add" />
</td></tr></table>
</form>
</body>
</html>
<?php
}
else
{
$error_list = "";
$todays_date = date( "Ymd" );
$reminder_date = $_POST['reminder_year'].$_POST['reminder_month'].$_POST['reminder_date'];
$reminder_date = $_POST['reminder_date']; // Modificado
if( empty($_POST['reminder_name']) )
$error_list .= "No Reminder Name<br />";
if( !checkdate( $_POST['reminder_month'], $_POST['reminder_date'], $_POST['reminder_year'] ))
$error_list .= "Reminder Date is invalid<br />";
else if( $reminder_date <= $todays_date )
$error_list .= "Reminder Date is not a future date<br />";
if( empty( $error_list ) )
{
// No error let's add the entry
mysql_query( "INSERT INTO reminder_events(`reminder_name`, `reminder_desc`, `reminder_date`) VALUES('".addslashes($_POST['reminder_name'])."', '".addslashes($_POST['reminder_desc'])."', '".addslashes($reminder_date)."')" );
// Let's go to the Reminder List page
Header("Refresh: 1;url=reminder_list.php");
echo <<< _HTML_END_
Reminder Added, redirecting ...
_HTML_END_;
}
else
{
// Error occurred let's notify it
echo( $error_list );
}
}
//$todays_date = date( "Ymd" );
?>
Que diferencia hay entre: "`reminder_date` date DEFAULT NULL," con "`reminder_date` date NOT NULL,"
de momento lo cambie asi:
TABLA
Código HTML:
CREATE TABLE IF NOT EXISTS `reminder_events` (
`reminder_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`reminder_name` varchar(100) NOT NULL,
`reminder_desc` text NOT NULL,
`reminder_date` date DEFAULT NULL,
PRIMARY KEY (`reminder_id`)
) ;