Jump to content

Date/MySQL Problem


paradoxweb

Recommended Posts

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?!?!?!

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.