- Sanitizing and validating email syntax
$email = $_POST['email']; //getting the posted email //sanitizing the email using FILTER_SANITIZE_EMAIL //removes all illegal e-mail characters from a string $email=filter_var($email, FILTER_SANITIZE_EMAIL); //validating the email using FILTER_VALIDATE_EMAIL //validates e-mail returning true if valid and false if invalid (filter_var($field, FILTER_VALIDATE_EMAIL)) ? TRUE : FALSE;
- Creating a function to validate and sanitize
function check($email) { $field=filter_var($field, FILTER_SANITIZE_EMAIL); return (filter_var($field, FILTER_VALIDATE_EMAIL)) ? TRUE : FALSE; }
Usage:
$email = $_POST['email']; if (check($email)==TRUE){ //send email }else{ echo "Invalid email!"; }
Validating emails with php
Sending emails with php
- Set up the variables:
$to = "email@address.com"; //where the email will go $subject = "Our Subject"; //the subject $message = "The message to send"; //the message $from = "you@email.com"; //from email $header = "From: $from"; //header including the from email
- Sending the email:
mail($to, $subject, $message, $header); //send the email
- Sending the email and returning a success or failure message
echo (mail($to, $subject,$message, $header)) ? "Email sent" : "Error sending email" ;
- Setting header to send html email:
$header = "MIME-Version: 1.0" . "\r\n"; $header .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; //add content type $header .= "From: $from"; //header including the from email
- Creating a function to send emails:
function mailit ($to,$subject,$message,$from){ $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= "From: <$from>" . "\r\n"; return (mail($to, $subject,$message, $headers)) ? TRUE : FALSE; }
Usage:
$to = "email@address.com"; //where the email will go $subject = "Our Subject"; //the subject $message = "<strong>Message</strong>The html message"; //the message $from = "you@email.com"; //from email echo (mailit($to,$subject,$message,$from )==FALSE) ? "Sending Failed!" : "Mail sent!" ;
Ternary Conditionals
I know most of you allready use them, but there are still people that don`t know about them, so to make the following tutorials easyer, I`ll do a small example.
First of all you must know that all you will see here is a simpler way to write not so complex if statements.
Traditional way:
if (condition) { echo "true"; } else { echo "false"; }
The shorter way:
echo (condition) ? "true" : "false";
Another example:
if (date("m")<12) { $var = 12-date("m") ." months till december"; }else{ $var = "It`s December"; } echo $var;
The shorter way:
$var = (date("m")<12) ? 12-date("m")." months till december" : "It`s December"; echo $var;
I hope you got it and this will make easyer for you to undersand the following tutorials.
Gadgets Advisor Technology News
Here`s a site I found called Gadget Advisor which contains technology news and reviews of the coolest gadgets and computer software out there. The best thing about this site is that they hand pick only the best and coolest of them all, so all you have to do is pick the right one for you.
A few of the things that got my eye are a list of the best Firefox extensions and I must say they picked the most useful ones, best Windows software downloads which includes 34 free applications of high quality and a review for Blaze Media Pro that gives us yet another choice of all-in-one audio and video convertor for CD, MP3, WAV, WMA, OGG, MPEG-1, MPEG-2, AVI etc.
Google Page Rank update protest
It seems Goole started the Page Rank update again after just two months. This time I got kicked again to pr 0. It seems weird since one of my sites that has very little traffic and backlinks went from 0 to 1 and this blog, that has over 15k backlinks went to 0. I`m starting to wonder what the real reason for being kicked is. I admit I did two sponsored posts and set up a ad sale in the sidebar. But still, I don`t see any reason to be punished like this. If you do paid posts, sell links, sell add space etc. using a intermediate site that Google doesn`t like (like ppp probably), you can kiss away your Page Rank. It`s really not fair.
I know Google supports open source, but do they realize that by taking my Page Rank they took my only source of income? It was little income, but kept my web hosting costs to 0. So now I ask them, why would I continue? It wasn`t a big deal, but the two little open source scripts here were downloaded over 5000 times. What`s the point now? Don`t get me wrong, I couldn`t care less, but it seems that Google keeps getting meaner, and unwillingly (I hope) forces us to do different things.
How is a little blogger supposed to make any money under these conditions?
As a protest, I`m removing all external ads from my sites, including AdSense.
If you would like to join or have an opinion on this, please comment.

