Here is a simple postcard system where a user writes a message, enters basic information, picks a postcard, and then submits the postcard. The chosen graphic is then sent to recipient with graphic attached to email message. Only works with PHP4. For a demo, go to http://www.zensmile.com/.
By : zensmile
<form action="thispage.php4" method="post">
<input type ="hidden" name="BeenSubmitted" value="true">
<?php
class mime_mail
{
var$parts;
var$to;
var$from;
var$headers;
var$subject;
var$body;
function mime_mail()
{
$this->parts=array();
$this->to= "";
$this->from= "";
$this->subject= "";
$this->body= "";
$this->headers= "";
}
function add_attachment($message,$name= "",$ctype= "application/octet-stream")
{
$this->parts[]=array(
"ctype"=>$ctype,
"message"=>$message,
"encode"=>$encode,
"name"=>$name
);
}
function build_message($part)
{
$message=$part[ "message"];
$message=chunk_split(base64_encode($message));
$encoding= "base64";
return "Content-Type:".$part[ "ctype"].
($part[ "name"]? ";name=\"".$part[ "name"]. "\"": "").
"\nContent-Transfer-Encoding:$encoding\n\n$message\n";
}
function build_multipart()
{
$boundary= "b".md5(uniqid(time()));
$multipart= "Content-Type:multipart/mixed;boundary=$boundary\n\nThisisaMIMEencodedmessage.\n\n--$boundary";
for($i=sizeof($this->parts)-1;$i>=0;$i--)
{
$multipart.= "\n".$this->build_message($this->parts[$i]). "--$boundary";
}
return$multipart.= "--\n";
}
function send()
{
$mime= "";
if(!empty($this->from))
$mime.= "From:".$this->from. "\n";
if(!empty($this->headers))
$mime.=$this->headers. "\n";
if(!empty($this->body))
$this->add_attachment($this->body, "", "text/plain");
$mime.= "MIME-Version:1.0\n".$this->build_multipart();
return(mail($this->to,$this->subject, "",$mime));
}
};
?>
<?php
if (isset($BeenSubmitted)) {
$num_errors = 0;
if (! strlen($to) > 0) {
echo "You must enter an e-mail address for the recipient.<br>";
$errors++;
}
if (! strlen($from) > 0) {
echo "You must enter your e-mail address.<br>";
$errors++;
}
if (! strlen($subject) > 0) {
echo "You must enter a subject for the e-mail.<br>";
$errors++;
}
if (! strlen($message) > 0) {
echo "You must enter some kind of message for the recipient.<br>";
$errors++;
}
if (! $fp = @fopen($postcard,"r")) {
echo "You must select a postcard from the left.<br>";
$errors++;
}
if ($errors == 0) {
$attachment=fread($fp,filesize("$postcard"));
$mail=new mime_mail();
$mail->from="$from";
$mail->to="$to";
$mail->subject=stripslashes($subject);
$mail->body=stripslashes($message);
$mail->add_attachment("$attachment","$postcard","image/jpeg");
if ($mail->send()) {
//if successful then writes info to a log file called log.txt.
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$filePointer = fopen("log.txt", "a");
fputs($filePointer, "$today\t\t$from has sent this email to $to.\n");
print ("Your email has been successfully sent!\n");
} else {
print ("Your email has been not been successfully sent because of a system error!\n");
}
}
}
?>
<p>Pick a postcard, fill out the information in the form boxes and click send! Make someone happy.
<p><img src="postcards/thumbnails/tn_butterfly.jpg" alt="" height="75" width="100" border="0">
<!-- Make sure that you have the correct path to the image in the value for the radio button(s) -->
<br><input type="radio" name="postcard" value="/home/username/web_directory/images/butterfly.jpg"> Butterfly
<p>Please fill out all of the information below.</p>
<p>Recipient's Email:
<br><input type="text" name="to" size="24" border="0">
<p>Your Email:
<br><input type="text" name="from" size="24" border="0">
<p>Subject of Email:
<br><input type="text" name="subject" size="24" border="0">
<p>Text of Message:
<br><textarea name="message" rows="6" cols="30"></textarea>
<p><input type="submit" value="Send Postcard"> <input type="reset">
</form>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Email Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
|
|
|
|
User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
|
|
|
|
Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable. FREE! Go There Now!
|
|
|
|
With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |