Jump to content

CMR

New Members
  • Posts

    2
  • Joined

  • Last visited

CMR's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. CMR

    A birthday Alert App

    What you could do is something along the lines of this: Table Structure: userid - int (10) auto_increment primary key, username - varchar (50), userdob - varchar (25), // Any Other Fields... Store the userbirthday in this format: dd month YYYY (Eg: 10 April 1970, 03 December 1986, etc...) Now, using php you could take that string and turn it into timestamp using strtotime(), eg: //.... $userBirthday = "29 December 1987"; // Eg: This variable may equal 10 April 1970, You WOuld get it from the DB, eg: $user['userdob'] $explode = explode(" ", $userBirthday); // Break it down into the day, month and year $birthDay = $explode[0]; $birthMonth = $explode[1]; $birthYear = $explode[2]; //Now we can add the birthDay, birthMonth and this year (eg: 29 December 2010) to make a timestamp and find out exactly when their birthday is this year $birthString = "".$birthDay." ".$birthMonth." ".date('Y'); $birthTimestamp = strtotime($birthString); // Next we can compare it to the current timestamp to see if they have already had their birthday this year, because if they have then there's no point continuing, they will just have to wait until next year $now = time(); // Current Timestamp if($birthTimestamp > $now) { // Okay Let's Continue // It's worth noting that this is a very basic example, so in reality you would want to actually check more throughly, eg: Okay their birthday may not be in the future, but what if it only happened a few hours ago? So what if it is their birthday today? This example would ignore that and only continue if their birthday is still yet to happen // Okay so we know their birthday hasn't happened yet, so can we find out when it is? $difference = $birthTimestamp - $now; // The time left between now and their birthday - In Seconds // You could then break this $difference down into minutes, hours, days, weeks, months etc.. eg: $type = 'Seconds'; $difference = $difference / 60; // This is now the time in minutes until their birthday $type = 'Minutes'; $difference = $difference / 60; // Hours $type = 'Hours'; $difference = $difference / 24; // Days $type = 'Days'; $difference = $difference * 0.14285; // Weeks $type = 'Weeks'; $difference = $difference * 0.22998; // Months $type = 'Months'; $difference = round($difference, 2); /****************************************************************************************************** * You will notice that the maths above is pretty crap, you may want to do it...well...unlike me... ******************************************************************************************************/ // Etc... // Again you'll want to do it more thoroughly though, eg: Checking if there is at least 1 hours left before converting to hours, otherwise you'll end up with it being "0" or "0.n" if you round() it // SO you could then simply display that if you wanted to, something like $newAge = date('Y') - $birthYear; echo "There is " . $difference . " " . $type . " left until your birthday. You will be ".$newAge." years old!<br>"; // Or you could do more checks, eg: you could display it only on round occasions, eg: 2 Months, 1 Month, 3 Weeks, 2 Weeks, 1 Week, etc... whatever you want really } //....
  2. CMR

    php forms

    Hi, If you want to add in a From: header, you can do this: /* Prepare autoresponder subject */ $respond_subject = "Thank you for contacting us!"; /* Prepare autoresponder message */ $respond_message = "Hello! Thank you for contacting us! We will get back to you as soon as possible! Yours sincerely, Your name www.yourwebsite.com "; /* Headers */ $headers = "From: MyName <myAccount@myDomain.com>\r\n"; $headers .= "Reply-To: anotherAccount@myDomain.com\r\n"; // Etc... /* Send the message using mail() function */ mail($email, $respond_subject, $respond_message, $headers); Looking at this line in your code: mail($myemail, $subject, $fname, $lname, $email, $login); I can't imagine that works does it? You seem to be passing the variables gained from your html form in the mail() function, when what you should be passing is: mail(to, subject, message, headers, extraparameters) What you'll want to do if you're trying to send an email with those variables displayed in it, is just put them in the message body somewhere, eg: /* Example Since I DOn't Know What You're Setting The Variables To */ $myEmail = $_POST['email']; $subject = 'My Subject'; $message = "Hello, Here are the details you entered: First Name: {$fname} Last Name: {$lname} Email: {$email} Login: {$login}"; $headers = "From: MyName <myAccount@myDomain.com>\r\n"; $headers .= "Reply-To: anotherAccount@myDomain.com\r\n" if($result) { mail($myemail, $subject, $message, $headers); header("location: register-success.php"); exit(); }else { die("Query failed"); } Regarding this bit: $message="$name just filled in your comments form.\n\nTheir phone number is:\n$phone\n\nThey live in:\n$city\n\nThey said:\n$comments\n\nTheir e-mail address is: $email"; if(mail($to,"Message From MC-HRSolutions.com",$message,"From: $email\n")) { echo "Thank you for your enquiry."; } else { echo "There was a problem sending the mail. Please check that you filled in the form correctly."; I tried it on my server and I didn't get any errors, so the error must be in a different section of the code. If you post the whole page of code, I'll see if I can see it. Also, you'll probably want to use the $headers as I outlined above for that section of code.
×
×
  • Create New...