Simple PHP email form with basic spam protection CAPTCHA

There are two pieces of code – the one which will display your email form, and a block of code to add into your “mailer” page – a page dedicated to sending the messages and displaying confirmations and errors.

Feel free to edit or tweak the code, download the images to your own server and use however you wish.

The form

<!-- email box ~ -->
<div style="width:400px;text-align:right;padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<form action="send.php" method="post" style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<p style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
Name: <input type="text" name="email_name" size=20><br>
Email: <input type="text" name="email_email" size=20>
<?php
$one = 1;
$two = 0;
$three = 0;
$four = 0;
while ($one % 2) $one = rand (10000,99999);
while (!($two % 2)) $two = rand (10000,99999);
while (!($three % 2)) $three = rand (10000,99999);
while (!($four % 2)) $four = rand (10000,99999);
?>
<br>Are you a human or internet virus?
<br>Choose the odd one out:
</p>
<div style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<input type="radio" name="email_valid" value="<?php echo $four ?>" Checked=1> <img src="http://Pushka.co/i/sys/lion.png" alt="This is a public domain image">
<input type="radio" name="email_valid" value="<?php echo $two ?>"> <img src="http://Pushka.co/i/sys/elephant.png" alt="This is a public domain image">
<input type="radio" name="email_valid" value="<?php echo $one ?>"> <img src="http://Pushka.co/i/sys/lifter.png" alt="This is a public domain image">
<input type="radio" name="email_valid" value="<?php echo $three ?>"> <img src="http://Pushka.co/i/sys/penguin.png" alt="This is a public domain image">
</div>
<p style="width:200; text-align:left;padding-bottom:0px; margin:0px 0px 0px 0px;padding-top:0px; padding-left:150px;">Message:</p>
<textarea rows="7" cols="30" name="email_msg" style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
</textarea><br>
<input type="submit" value="Send">
</form>
</div>

The sender and confirmation message generator (should be in the main text region of your regular website theme)

<div title="main"><h1>Send</h1>
<div style="width:400px;"><br /><br />
<?php
$name = $_POST["email_name"];
$email = $_POST["email_email"];
$valid = $_POST["email_valid"];
$message = $_POST["email_msg"];
$error = 0;
if (strlen($email) == 0) {
echo "<img src='http://Pushka.co/i/sys/cross.png'> Please enter an email<br>";
$error =1;}
elseif (strpos($email,"@") === false | strlen($email) < 6){
echo "<img src='http://Pushka.co/i/sys/cross.png'> Please enter a valid email in the form X@X.XX<br>";
$error=1;}
if (strlen($message)==0){
echo "<img src='http://Pushka.co/i/sys/cross.png'> Please enter a message<br>";
$error=1;}
if ($valid%2){
echo "<img src='http://Pushka.co/i/sys/cross.png'> There was an error with the image validation, please select the odd one out.<br>";
$error=1;}
if (strlen($name) == 0) $name = $email;
$message = "This message was sent from Pushka.co - from " . $name . " \n ---------------------------- \n \n " . $message . " \n \n ---------------------------- \n \n \n";
if ($error==0){
echo "<img src='http://Pushka.co/i/sys/tick.png'> Email Sent<br><br><FORM><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'> </FORM> <br>";
$to = 'you@mail.com';
$subject = 'Message from Pushka.co';
$headers = 'From: ' . $email . " \r\n" .
'Reply-To: ' . $email . " \r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
else{
echo "<br><FORM><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'> </FORM> <br>";
}
?>
<br><br>
</div>
</div>

 Here is an example

The emails are sent to the Cosmic Owl, who may or may not ever respond to you

  • Name:
    Email:
    Are you a human or internet virus?
    Choose the odd one out:

    This is a public domain image This is a public domain image This is a public domain image This is a public domain image

    Message:


    Send



    Please enter an email
    Please enter a message




You can have both blocks of code on the same page if you have action=”"

Google IO 2011 – signing in from Australia

I’m currently watching the bginning of Google IO Develoers conference from Australia ~

so exciting ~ it’s the 1st I’ve listened to ~

I’ll give live updates ~ (though on the Google IO 2011 website, there are also live streming, updates and announcements)

  • Update to Honeycomb, Ice-cream Sandwich (I mised this)
  • Android market + Movie rentals (like on YouTube)
  • Google Music Beta – online iTunes replacement in the cloud with auto sync
  • Open accessories - anyone can make any type of accessories that work with Android
  • Android at Home – Android can work with any item in your house, if inbuilt, or if you connect to a receiver

I can’t believe how smooth and amazing the Google IO live stream is ~ there must be thousands watching and it doesn’t skip a beat~

There were 2 main streams on the live streaming  ~ Android and Chrome – both of which I’m really interested in – wish I could watch it all ~ I think it will all be released soon~

And huge news for browsers and the killing of IE6

  • There is a plugin called Google Chrome Frame, which can be installed on machines without admin privaliges, that renders web pages through Chrome in IE if the webpage has opted in (with a meta tag) – so websites can use HTML 5, modern flash, 3d graphics etc. in IE6 with this plugin.

Also Google Open Fonts is exciting:

  • Rich fonts like what is used in print, Google hosts them, so there isn’t any down time, there is no licencing issues, because it’s open, and Google handles cross-browser quirks and browser updates etc., option for compression, optimisation, only download characters you need, caching.

Featured Video rather than Image for WordPress

Some templates have a featured image, but sometimes you want a video instead… But not all the time..

You can set some custom fields, and then add in PHP – if the field has something in it – display the embedded video (at the same size the featured image would have been…)

The text in the custom field should just be the ID code for YouTube or Vimeo (or you can add your own if you want… but you need to add the embed code to the PHP)

The code gets the ID and inserts it into the embed code.

<?php
if (post_custom(‘a YouTube ID Code’)) {
echo ‘<iframe width=”640″ height=”402″ src=”http://www.youtube.com/embed/’ . get_post_meta($post->ID, ‘a YouTube ID Code’, $single = true) . ‘” frameborder=”0″ allowfullscreen></iframe>’ ;
}
else if (post_custom(‘a Vimeo ID Code’)){
echo ‘<iframe src=”http://player.vimeo.com/video/’ . get_post_meta($post->ID, ‘a Vimeo ID Code’, $single = true) . ‘?title=0&amp;byline=0&amp;portrait=0″ width=”400″ height=”225″ frameborder=”0″ webkitAllowFullScreen allowFullScreen></iframe>’ ;
}else{
?>

 

add the YouTube or Vimeo ID code to a custom field:

  • a YouTube ID Code
  • a Vimeo ID Code

EG:

  • bH9tJXm2Bcw
  • 31934775

From the original YouTube links:

  • http://www.youtube.com/watch?=bH9tJXm2Bcw&feature=channel_video_title
  • http://vimeo.com/31934775

Shift Joomla and WordPress installs

  • Copy HTML/CSS/etc. – folders. everything
  • Move the database

Login to old cPanel -> PHPmyAdmin
select databse, check all tables, “export” – all (custom – all options)

Go into new PHPmyAdmin
import all

edit (WP-config.php,. config.php (in Joomla)

Edit the database location:

  • Databse name (same)
    But – might be something like:
    old DBS name is “shop”
    new name is “rotapixt_shop”
  • Server (local host if it is on the same server, else the address (EG: http://cpanel.something.com)
    it’s possible to install the HTML files on one FTP account server, and install the database on a different server….
  • Database user username:  (hosting account username/ password login)
  • Database user password

Note:
In website hosting – you have an account username and password, this is the same for :

  • FTP account
  • cPanel login (maybe PHPmyadmin has a different password)
  • Database / MySQL username / password (would be the same as PHPmyAdmin)

Joomla – Configuration.php:

  • host $host
  • DB name $db
  • username MYSQL $user
  • pass $password

WordPress – wp-config.php

  • commented with labels ~

LOCAL HOST =

HTML goes in the htdocs folder

http://localhost/cpanel(then click “PHPMYADMIN” to edit database

  • DBS name = whatever you call it in PHPmyadmin
  • server = localhost
  • username = root
  • password = “” (nothing)

My default WordPress Settings

I always set this stuff up like this:
  • General
    • Site title/tagline
  • Writing
    • Default Post category – change name from default to (something with relevant keywords in it)
      Edit this in Posts->Categories
  • Reading
    • Front page displays “static page”
      • Create 2 new blank pages called  “home” and “blog” – set these two ~
  • Discussion
    • Disable the 2 emailers when people comment
  • Permalinks
    • Custom
      • /%category%/%postname%/

Stylebot Chrome Browser Stylish

Stylebot – I love this plugin.

It’s like stylish/ greasemonkey for FireFox, but simpler to make your own edits to websites.
You just go to a website you want to edit, and click areas of the page you want to change, or add your own CSS to add to that domain.

Maybe not that powerful, but It could get better ~

Here are my first ones, completely cleaning some websites:

SMSfun.com.au

This website can be so obnoxious, covered in bright colours and flashing images, but now theres:

body {
background-image: none;
background-color: #ccc;
}

#contentright, #tblrightcolumn, #sitebanner, #leftcolumn , #sitebanners, #featured, #regright, .features, #weeklypollbox, #joinnowbox, #welcomeblock {
display: none;
}

#sitenav {
margin-top: 97px;
}

 

Before:

2After

1

whois.domaintools.com - Removing the Sidebar

.main_right_content, #center-content-right, #main-left-content, #google-ads-container, iframe, #aswift_0_anchor, .whois-social-media float-row, .addthis_toolbox, .whois-social-media {
display: none;
}

.main_left_content, .float-row, .rounded-grey-tab, .tab-panel, .whoisTabs, .tab-panel-header, .unselectable, .tab-panel-header-plain, .tab-panel-body, .tab-panel-body-top , .tab-strip-wrap, #center-content-left {
width: 100%
;
}

.right {
float: left;
}

domaintools.com

#dt-nav-wrapper-banner, .right-column, .things-to-do, .float-row, .vert-pad-10
{
display:none;
}

YouTube

.homepage-side-block, .yt-alert-promo, .shmoovies-list-container, #ALL-content , .watch-sidebar-section, #watch-sidebar , .browse-content , #__ffYoutube3, #ad_creative_1, #homepage-side-content, .h2-links-black {
display: none;
}

FaceBook – remove the blue bar at the top (make it white)

.slim #blueBar {
border-bottom: 1px solid #fff;
}

#blueBar {
background-color: #fff;
}

#pageLogo a {
background-color: #fff;}

biblegateway.com

#home-picks , #votd-box, .section-box, #merch-bottom, #rotate-link, #social-media-links, #top-link, #gospel-com-results, .with-alert, .results-head, .passage-share-buttons , .share-buttons {
display: none;
}

#body {
min-height: 200px;
}

mobile.biblegateway.com

#merch-bottom, #home-picks, .with-alert, #sections-left-col, #welcome-box , #mobile_block , #social-media-links, #top-link {

display: none;
}

.max_width {
max-width: none;
margin: 1px 5px 0 ;
}

#main-col {
min-height: 10px ;
}

#sig p {
position: relative;
float: left;
padding-left: 30px;
}

 

double click animation, double right click GIF animation

I made these two animations, since I needed them for explaining that in embedded Google Maps, you can double left or right click to zoom in and out..

Double Click GIF Animation
left-click-double-gif-animationDouble Right Click GIF Animation
right-click-double-gif-animation

You can download the ZIP of both GIFs and the photoshop file, if you want to edit it – you can make single click too
The original image is GPL licence, as are my derivative edits.

Double click Animation – GIF, double right click ZIP file - Free for any use.