Jump to content

How can I setup if user select date matches today's date, send out the message


akoh

Recommended Posts

Hi,

 

Basically what I am trying to achieve here is if sendDate (select by user on the form) matches today's date, send out the autoresponder automatically.

 

I am still learning PHP MySQL and here are my code:

 

HTML Form (i am using datetimepicker javascript):

<label for="sendDate">When would you like<br /><span style="margin-top:-5px; float:right;">the card to be sent?</span></label>

<input id="sendDate" name="sendDate" type="date" size="25" value="<?php echo $_POST['sendDate']; ?>"><a href="javascript:NewCal('sendDate','mmddyyyy')"><img src="img/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>

 

When submit, the date store in MySQL.

 

Here is my process.php code (for the autoresponder):

 

      // Send autoresponder

      $template = 'emailer/autoresponder.html';

      $fd = fopen($template,"r");

     

      $sdate = date("M-d-Y");

     

      $query="SELECT ID,email,sendDate FROM test WHERE sendDate='".$sdate."'";

      $result=mysql_query($query) or die ($query . "<br />" . mysql_error());

     

      if($sdate==$sendDate)

      {

     

      $TO = $_POST['rvar_card_email'];

      $SUBJECT = "Mikey Network Donation - E-Card";

      $FROM = "info@mikeynetwork.com";

     

      $HEADER = 'MIME-Version: 1.0' . "\r\n";

      $HEADER .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

      $HEADER .= "From: $FROM";

      $MESSAGE = fread($fd, filesize($template));

     

      $original = array("{rvar_card_description}", "{rvar_card_message}", "{rvar_card_signature}");

      $replace = array($rvar_card_description, $rvar_card_message, $rvar_card_signature);

      $MESSAGE = str_replace($original,$replace, $MESSAGE);

     

      mail($TO,$SUBJECT,$MESSAGE,$HEADER);

 

      fclose($fd);

      }

 

Please help. Thank you.

Link to comment
Share on other sites

No, I don't say that you should remove it. Although...

I don't see where you put the values from your database into variables. Therefore I don't see the use of mentioned if-statement. Normally, after you successfully complete a SELECT-statement, you put the fields in an array with something like:

 

while($row=mysql_fetch_array($result)){
   .
   process the databasefields with $row['fieldname']
   .
}

 

In your code above I do not see where you use any of the fields from your database. The variable $sDate is set prior to your SELECT, and in your SELECT you could use: WHERE sendDate = NOW();

After that, you don't need to check if $sDate == sendDate, because you already SELECTed them...

 

Link to comment
Share on other sites

Hi EdwinPaul,

 

I have tried the suggestion you made, it's now storing all the date user select into MySQL but it doesn't send on the date specified on my date picker js.

 

I am not sure what I did wrong here:

                // Send autoresponder
      $template = 'emailer/autoresponder.html';
      $fd = fopen($template,"r");
      
      $sdate = date("M d Y");
      
      $query="SELECT ID,email,rvar_card_email,rvar_card_description,rvar_card_message,rvar_card_signature,orderdate FROM test WHERE orderdate=NOW()";
      $result=mysql_query($query) or die ($query . "<br />" . mysql_error());
      
      while($row=mysql_fetch_array($result)){
      echo $row['ID'] . " " . $row['email'];
      echo "<br />";
      echo $row['rvar_card_email'];
        echo "<br />";
      echo $row['orderdate'];
        echo "<br />";
      echo $row['rvar_card_description'];
        echo "<br />";
      echo $row['rvar_card_message'];
        echo "<br />";
      echo $row['rvar_card_signature'];
        echo "<br />";
      }
      
      $TO = $_POST['rvar_card_email'];
      $SUBJECT = "XXX";
      $FROM = "[email]xxx@xxx.com[/email]";
      
      $HEADER = 'MIME-Version: 1.0' . "\r\n";
      $HEADER .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
      $HEADER .= "From: $FROM";
      $MESSAGE = fread($fd, filesize($template));
      
      $original = array("{rvar_card_description}", "{rvar_card_message}", "{rvar_card_signature}");
      $replace = array($rvar_card_description, $rvar_card_message, $rvar_card_signature);
      $MESSAGE = str_replace($original,$replace, $MESSAGE);
      
      mail($TO,$SUBJECT,$MESSAGE,$HEADER);

      fclose($fd);

Really appreciate it.

Link to comment
Share on other sites

Hi EdwinPaul,

 

The date picker was in my form:

 

         

<label for="orderdate" style="width:300px; text-align:left;">When would you like the card to be sent?</label>

		<input type="button" onClick="alert(this.form.orderdate.value)" value="Show date value passed">
            <script>DateInput('orderdate', true)</script>

 

 

and this script in the <head>:

 

<script type="text/javascript" src="js/calendarDateInput.js"></script>

 

Let me know if you need to see more..

 

Thanks.

 

Link to comment
Share on other sites

Hi akoh,

I took a few moments, because I downloaded your datapicker and made a testfile:

 

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/calendarDateInput.js"></script>
</head>
<body>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' ){
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
?>

<form action="" method="post">
When would you like the card to be sent?<br />
<script>DateInput('orderdate', true, 'DD-MM-YYYY')</script>
<input type="submit" value="Enter" />
<input type="button" onClick="alert(this.form.orderdate.value)" value="Show date value passed">
</form>

</body>
</html>

and this works. After clicking on "Enter" my $_POST['orderdate'] is filled with the date I entered.

Link to comment
Share on other sites

Thanks for the reply, EdwinPaul. It works now. However, my ultimate aim is to be able to send the autoresponder (code above) based on the "orderdate" by user. For example, when user fill out the form and select a specify date to send the card. When the actual date arrives, the autoresponder (ecard) send out to the recipient email address entered on my form.

 

Do you think this is possible?

 

Thanks again for all your help, really appreciate it.

Link to comment
Share on other sites

Yes, that should be possible. If you use a 'cronjob' it runs when you want it, without you having to do anything. You could also run that job yourself every day to send the ecards. You have to put the date the ecard should be send in your database, and also if you already sent it.

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.