paradoxweb Posted August 10, 2008 Share Posted August 10, 2008 Hey Everyone, Need a bit of help here, I have made a script that sends an email to everyone that has been in the database for three days, here is the line of code that gets the date : $day = date("d"); $month = date("m"); $year = date("Y"); $prevthreets = mktime(0,0,0,$month,$day -3,$year); $prevThree = date("Y-m-d",$prevthreets); And Here is the code that sends the emails: $con = mysql_connect("localhost","goskydi_admin","admin123"); if(!$con) { die("Could not connect: " . mysql_error()); } mysql_select_db("goskydi_customers",$con); //Three Day Email $result = mysql_query("SELECT * FROM customers WHERE date = '".$prevThree."'",$con); while($row = mysql_fetch_array($result4)) { $sender = "isender@email.com"; $recipient = "recipient@email.com"; $subject = "Insert Subject Here"; $body = "Insert Email Content Here"; $headers = "From: $sender\r\n" . "Reply-To: $sender\r\n" . 'X-Mailer: PHP/' . phpversion(); echo "<br>"; if (mail ( $recipient, $subject, $body, $headers)) echo "Mail Sent!"; else echo "Failed sending email"; echo "<br>"; } mysql_close($con); Could some one tell me whats going on, I tried hard coding the date into the mysql query and that worked, but when its getting it from a variable, it doesn't work, Can someone please help me?!?!?! Quote Link to comment Share on other sites More sharing options...
deadlyp99 Posted August 10, 2008 Share Posted August 10, 2008 Not sure if this is the problem, but you formatted prevthreets as m-d-y, and prevThree as y-m-d, That could be the problem, but it also matters how the date is formatted in the database. I personally prefer to use the time() function instead others because you work with hard numbers and can do simple math. $prevthreets = time() - (60 * 60 * 24 * 3); // 60 seconds * 60 minutes * 24 hours * 3 days Then all that is left is to make sure the formatting of prevThree matches the datbases. If the database shows m-d-Y, giving it Y-m-d could raise errors/ Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 10, 2008 Share Posted August 10, 2008 I would just do the entire thing in your query: $result = mysql_query("SELECT * FROM customers WHERE `date` > CURDATE() - INTERVAL 3 DAY,$con); FYI, the mail() function wont be much use for large volume emails. Quote Link to comment Share on other sites More sharing options...
coder500 Posted August 10, 2008 Share Posted August 10, 2008 the mail() function wont be much use for large volume emails Can anyone please tell whether the above statement is correct. If so why? Because we can access mail id from database using for loop/while loop , and we can set $to="mail id from database" and use mail() function. Thanks Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 10, 2008 Share Posted August 10, 2008 Quoted from the manual: Note: It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient. For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages. Quote Link to comment Share on other sites More sharing options...
coder500 Posted August 11, 2008 Share Posted August 11, 2008 Thanks GingerRobot ! Quote Link to comment Share on other sites More sharing options...
unrelenting Posted August 11, 2008 Share Posted August 11, 2008 while($row = mysql_fetch_array($result4) Shouldn't that be: while($row = mysql_fetch_array($result) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.