Forum Moderators: coopster

Message Too Old, No Replies

Simple mail file not working.

         

dkin

9:47 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



I have created a file that will parse my mysql db table. if the date entered the row was entered is equal to the date today I would like it to email me the html for a link to all the items emailed, if there are none I would like an email saying that. This is what I have thus far.

<?php

$date = date("m/d/Y");
$link = mysql_connect("localhost","******", "*****") or die ("couldnt connect: " . mysql_error());
mysql_select_db("eqoagui_nuke1",$link) or die ("couldnt select db: " . mysql_error());
$results = mysql_query("SELECT * FROM nuke_item_database",$link);
$myrow = mysql_fetch_array($results);
$today = "myrow[date]";

if ($today == "$date") {

do {

$items = "<a href=\"modules.php?name=$module_name&file=item_page&id=$row[id]\"><b>".$row["Item_Name"]."</b></a>\n";

}

while ($myrow = mysql_fetch_array($results));

$myemail = "me@me.com";

mail("$myemail", "Daily updates to your database.", $items,
"From: mysite.com\r\n" .
"Reply-To: none\r\n" .
"X-Mailer: PHP/" . phpversion());

}

else {

$myemail = "me@me.com";

mail("$myemail", "No items added today.",
"From: mysite.com\r\n" .
"Reply-To: none\r\n" .
"X-Mailer: PHP/" . phpversion());

}

?>

I am only receiving emails saying that no items were entered, I do not know why.

Also I would like to set up a cron job to run this file but no matter what I do I cannot get the cron to run a php file, thoughts?

[edited by: jatar_k at 10:28 pm (utc) on July 20, 2004]

dkin

10:53 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



anyone?

dkin

1:28 am on Jul 21, 2004 (gmt 0)

10+ Year Member



if I did not explain it very well I would not be suprised.

If anyone does not understand please post and I will rewrite it best I can.

Timotheos

7:52 am on Jul 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dkin,

It's been a busy day.

First off this line looks suspect
$today = "myrow[date]";

That should be
$today = $myrow['date'];

Second of all you'll want to make sure your date formats are similar. It's pretty rare to see dates stored like 7/20/04. Usually in mySQL it 2004-07-20 or a timestamp format.

Now that I've said that have you considered using the WHERE syntax in your SQL query?

SELECT * FROM nuke_item_database WHERE date = CURDATE()

I'm not sure but I think you'll still have to check on the date formatting for this to work. Check out the mySQL manual under Date and Time functions [dev.mysql.com]. This will select only the items with the current date so you don't need to use php to loop through to find them. You only need to check to make sure something is there then loop through just to send emails.

Hope this helps,
Tim

dkin

8:06 pm on Jul 21, 2004 (gmt 0)

10+ Year Member



Ok I have my date variables set to $date = date("Y-m-d"); now.

But with the select part how would I put the results into variables so I could email them to myself?

dkin

9:09 pm on Jul 21, 2004 (gmt 0)

10+ Year Member



It is sending me the data but it is not sending the variables so I am receiving thisa in my email.

<a href="modules.php?name=Item_Database&file=item_page&id="><b></b></a>

And it will not send me more than one.

dkin

9:54 pm on Jul 21, 2004 (gmt 0)

10+ Year Member



anyone know how I can get all the results sent to me and the variables in place?

dkin

2:06 am on Jul 22, 2004 (gmt 0)

10+ Year Member



anybody, please this is very crucial to my website operation.

Thank you

dkin

6:03 pm on Jul 22, 2004 (gmt 0)

10+ Year Member



now that it is morning I am hoping I will get a response.

Thanks

Timotheos

7:06 pm on Jul 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dkin,

Beware this is totally untested. Good luck.

<?php

$link = mysql_connect("localhost","******", "*****") or die ("couldnt connect: " . mysql_error());
mysql_select_db("eqoagui_nuke1",$link) or die ("couldnt select db: " . mysql_error());
$results = mysql_query("SELECT * FROM nuke_item_database WHERE date = CURDATE()",$link);

if (mysql_num_rows($results)==0) {
$message = "No items added today";
}
else {
$message = "Daily updates to your database\r\n";
while ($row = mysql_fetch_array($results)) {
$message .= "<a href=\"http://www.mysite.com/modules.php?name=" . $module_name . "&file=item_page&id=" . $row['id'] . "\"><b>" . $row['Item_Name'] . "</b></a>\r\n";

}
}

$to = "me@me.com";
$subject = "Daily updates to your database";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: Me <me@mysite.com>\r\n";
$headers .= "Reply-To: none\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

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

echo "Results have been sent";
?>

dkin

8:56 pm on Jul 22, 2004 (gmt 0)

10+ Year Member



actually I tampered with it a bit and it works very well for an untested script.

One thing, currently it is sending links, what I would like is for it to send the html to me so that I can cut and paste it into a page, I have fooled around with special characters and such but cant seem to get the code right.

I am sure this is very easy I just cant seem to get it right.

coopster

10:14 pm on Jul 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Send the content type as text/plain.

dkin

12:37 am on Jul 23, 2004 (gmt 0)

10+ Year Member



works great, I never would have thought of that.

Thats why your the moderator.

Now do you know how I would set up a cron job through cpanel to activate this file?

I try and I get this error sent to my email.

/bin/sh: line 1: itememail.php: command not found

dkin

5:48 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



everything is working brilliantly, thanks alot.