Improving the Simple Contact Form
A few weeks back, we learned how to build a simple
contact form to allow our users to send us feedback directly from a
site.
As noted in the comments, there were a few shortcomings with the contact
form. Most notably, there was no spam protection whatsoever. Additionally,
if the user made a mistake, their message would be lost, which is
extremely inconvenient.
To make this contact form ready to use on a real website, we'll be adding
both a basic spam protection system and the ability to store the message
in a session in case the user makes a mistake.
NOTE: Like all projects built on this blog, this is being
presented as a teaching exercise and a demonstration, so be sure to
double-check it before...
read more
Send HTML and Plain Text Versions of Email
Recently, I've been dealing with sending email from applications an awful
lot. At first glance, sending a basic message from PHP is easy:
<?php
mail('test@example.com', 'Subject Line', 'A message!');
?>
Sending complex messages with HTML formatting and/or attachments, however,
can be tricky. Today, we're going to cover sending HTML email to a user
while still including a plain text version for email clients that don't
support HTML.
See the Demo | Download the Source
Part One: Understanding Email Structure
Basic email structure is something like this:
To: someone@example.com
Subject: Test Email
From: Test <testing@example.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx"
X-Nonspam: None
--==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
This Is a Plain Text Email
This message has no HTML. http://w3schools.com
--==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<body>
<h1>This Is an HTML Email</h1>
<p>
This message is composed in <a
href="http://w3schools.com">HTML</a>.
</p>
</body>
</html>
--==PHP-alt_xd50dc5b6ee7a015fb67e36ba692a93ad961d5f7dx--
This looks a little daunting at first, but if we take...
read more
ITT #16: Create a Template Parsing System with PHP
One of my most recent obsessions has been with simplifying my custom CMS to
allow me to generate full sites without changing anything but HTML
template files and a basic configuration file. In this week's Instant Tip Tuesday, we'll explore
one of the ways we can dynamically generate output and wrap it in a
template file.
NOTE: This is a proof-of-concept type of thing, not a
production-ready script. Be aware that I haven't used a script like this on
a real site, and therefore have no idea if it's fast, effective, or even
useful. For now, this is just a "hey, cool!" sort of thing; use with
discretion.
Download the Files
So, What Are We Trying to Do?
To try and explain what our goal is...
read more
ITT #15: Create a Simple Contact Form
NOTE: This entry has been improved upon by adding spam
protection and sessions. It's strongly recommended that you use the newer version of the
simple contact form.
Making yourself accessible is one of the most important aspects of a site
that aims to connect with its audience online, and nothing makes a person
more accessible than an easy-to-use contact form.
In this week's Instant Tip
Tuesday, we'll build a simple (less than 200 lines of code, including
comments) contact form that will allow users to contact us without needing
to open their mail client or copy and paste our email address into their
web mail service. Our finished contact form will do the following: