Jump to content

Recommended Posts

Hi, I had an account a while back but lost it lol... need a little help... prob simple but cant figure it... i want to have a user input a date and for php to work out that date 120 days later... thing is i want this to be emailed... basic code so far and it works but cant get it to work with the date maniplation.

<?php


// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "my email is here!!!";


$Subject = "DEAL:";
$Deal = Trim(stripslashes($_POST['Deal']));
$Sites = Trim(stripslashes($_POST['Sites']));
$TOS = Trim(stripslashes($_POST['TOS']));
$SST = Trim(stripslashes($_POST['SST']));
$DV = Trim(stripslashes($_POST['DV']));
$DCP = Trim(stripslashes($_POST['DCP']));
$NOTES = Trim(stripslashes($_POST['NOTES']));
$Status = Trim(stripslashes($_POST['Status']));

// validation
$validationOK=true;

if (Trim($Deal)=="") $validationOK=false;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
  exit;
}


// prepare email body text

$Body = "";
$Body .= "Deal Done By: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "\n";
$Body .= "Deal Name: ";
$Body .= $Deal;
$Body .= "\n";
$Body .= "\n";
$Body .= "Number Of Sites: ";
$Body .= $Sites;
$Body .= "\n";
$Body .= "\n";
$Body .= "Type Of Sale: ";
$Body .= $TOS;
$Body .= "\n";
$Body .= "\n";
$Body .= "Supplier Signed To: ";
$Body .= $SST;
$Body .= "\n";
$Body .= "\n";
$Body .= "Deal Value: ";
$Body .= $DV;
$Body .= "\n";
$Body .= "\n";
$Body .= "Notes: ";
$Body .= $NOTES;
$Body .= "\n";
$Body .= "\n";
$Body .= "Date Can Be Processed: ";
$Body .= $DCP;
$Body .= "\n";
$Body .= "\n";
$Body .= $Status;
$Body .= "\n";
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");




// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=oksub.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/225643-php-date-help/
Share on other sites

I don't know what format $DCP is in or what format you want the new date in, but here's an example:

 

//convert to unix timestamp
$DCP = strtotime($DCP);
//add 120 days to timestamp and format it as month-day-year
$DCP = date('m-d-Y', strtotime('+120 days', $DCP));

Link to comment
https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165055
Share on other sites

If you're using PHP 5.3, you may also be interested in the date interval class.

 

Also, if you're using stripslashes, you're doing something wrong.  Stripslashes is only necessary if you have magic_quotes turned on, and that is widely considered to be bad practice.

 

-Dan

Link to comment
https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165062
Share on other sites

   <p>Date Can Be Processed:* <br>
<input type="text" name="DCP" class="field" value="<?php
echo date("d/m/Y");
?>" tabindex="7">

 

above is the input for the user to input the date, its set to a default atm but if the customer inputs their own i want it to give the date +120 in D/M/Y format.

 

im not sure how to get that in to the exisiting code so it outputs in the email sent.

Link to comment
https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165073
Share on other sites

January 1, 1970 is "zero time," that's when the Unix epoch began.  Any invalid date math comes out to that date.

 

You keep saying you're manipulating the date...but I haven't actually seen any date functions in any of your code.

 

m/d/Y is ambiguous, because europeans use m/d/y.  You can switch to a datepicker that returns data in Y-m-d, that may help. 

 

Standard debugging steps apply here.  Echo what you have.  Run strtotime.  Echo what that gives you.  etc.

 

echo date("Y-m-d", strtotime("1980-03-14") + (60*60*24*120));
//outputs: 1980-07-12

-Dan

 

Link to comment
https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165997
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.