- 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!"; }
Tag Archives: php
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.
Free Social Bookmark Script generator
Here`s a free Social Bookmark Script generator I made.
It`s actually a clone of another website that I don`t want to mention.
Check it out, you might like it and it could get you lots of backlinks.
Host your own Social Bookmark Script generator website.
Offer a free service to the world.
Get free backlinks.
- Usage:
- Download the zip archive and unzip it on your local machine.
- Edit terms.htm page.
- Edit bookamrks.php at line 2 and define the script folder and image folder.
- Upload all the files to your website root(bookmarks.php, terms.htm and bookmark-images folder)
- Include bookmarks.php in your page using php include function or design around it and rename it to index.php
- Download:
- Social Bookmark Script generator
AdSense Revenue Sharing 1.1
New version 1.1 AdSense Revenue Sharing plugin released.
New in version 1.1
- Fixed add hit count
- Fixed ad preview
- Once you click outside the field you edited the preview will be updated. Once you save it, it will show the new data.
- Fixed multiple post page display
- Pages that show more than one post like main page, archive page, search page will only display ads in the latest
post added on the certain page (first post on page)
- Pages that show more than one post like main page, archive page, search page will only display ads in the latest
- Added smart ad count
- If you accidentally enter more than 3 quicktags in a post it ignores them and ads one ad at the end of the post.
Same thing happens on multiple post pages.
- If you accidentally enter more than 3 quicktags in a post it ignores them and ads one ad at the end of the post.
- Added new option ->Show all
- If you enable this option all the quicktags you added will be ignored and one ad will be placed at the end of every
post/page. When you disable this options ads will be shown again only in posts that have a quicktag.
- If you enable this option all the quicktags you added will be ignored and one ad will be placed at the end of every
You can grab it here: AdSense Revenue Sharing 1.1