Jump to content

Recommended Posts

Hey guys, I need some fresh air on this problem. Basically I am building an application for myself to select all Emails from MYSQL database where the date is between something I enter in a form, and another date, and then send an email saying that their account is expired.

 

Whenever I POST the date into PHP, it returns nothing. Yet if I keep the query "SELECT Email FROM Customer" it selects all the emails and sends an email.

 

Here is the code I am working with. The date format that MYSQL is using is 2008-10-14 00:00:00

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
include 'config.inc.php';

if (isset($_POST['expired'])){
$beginDate = $_POST['beginDate'];
$endDate = $_POST['endDate'];

echo $subject;
        $query="SELECT Email FROM Customer WHERE UDFDate2 >= $beginDate and UDFDate2 <= $endDate";
$result=mysql_query($query);
        $num=mysql_num_rows($result);
        $i=0;
        while ($i < $num){
$email=mysql_result($result,$i,"Email");                        
                mail($email, $subject, $message, "From: Sender<Sender@sender.com>\nX-Mailer: PHP/" . phpversion());
                echo "Email sent to: " . $email . "<br />";
        
                $i++;
                                
        }
}


?>
<br />

<form name="email" action="<?=$_SERVER['admin2423.php']?>"  method="post">
  Begin Date 
  <input name="beginDate" type="text" size="10"> 
  End Date
  <input name="endDate" type="text" size="10"> 
  <input type="submit" name="expired" value="Email!">
</form>
</body></html>



 

I used this code as a skeleton

 

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<?php
include './inc/config.inc.php';

if (isset($_POST['submit']))
{

        $subject = $_POST['subject'];
        $message = $_POST['message'];

        
        $query="SELECT email FROM users_test";  //Change users_test to users
        $result=mysql_query($query);
        $num=mysql_num_rows($result);


        $i=0;
        while ($i < $num) 
        {
        
                $email=mysql_result($result,$i,"email");
                        
                mail($email, $subject, $message, "From: Someone<someone@somewhere.com>\nX-Mailer: PHP/" . phpversion());
        
                echo "Email sent to: " . $email . "<br />";
        
                $i++;
                                
        }
}
?>
<br />

                
<form name="email" action="<?=$_SERVER['email.php']?>" method="post">

Subject
<br />
<input name="subject" type="text" size="50" id="subject"><br /><br />
Message
<br />
<textarea name="message" cols="50" rows="10" id="message"></textarea>
<br /><br />
<input type="submit" name="submit" value="Email!">
        
</body>
</html>

 

Any help would be greatly appreciated. I need to only get past this date problem, then I know I can tackle what kind of message I want to send. Thanks!

 

try this *untested*

 

<?php
//2008-10-14 00:00:00
$beginDate = date("Y-m-d H:i:s", strtotime( $_POST['beginDate']));;
$endDate = date("Y-m-d H:i:s", strtotime( $_POST['endDate']));

$query="SELECT Email FROM Customer WHERE UDFDate2 BETWEEN '$beginDate' AND '$endDate' ";
?>

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.