Email Code

  Home arrow Email Code arrow Simple Postcards

Simple Postcards
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5

    Table of Contents:



    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

    By : zensmile

    <form action="thispage.php4" method="post">
    <input type ="hidden" name="BeenSubmitted" value="true">

    class mime_mail

    function mime_mail()
    $this->to= "";
    $this->from= "";
    $this->subject= "";
    $this->body= "";
    $this->headers= "";

    function add_attachment($message,$name= "",$ctype= "application/octet-stream")

    function build_message($part)
    $message=$part[ "message"];
    $encoding= "base64";
    return "Content-Type:".$part[ "ctype"].
    ($part[ "name"]? ";name=\"".$part[ "name"]. "\"": "").

    function build_multipart()
    $boundary= "b".md5(uniqid(time()));
    $multipart= "Content-Type:multipart/mixed;boundary=$boundary\n\nThisisaMIMEencodedmessage.\n\n--$boundary";
    $multipart.= "\n".$this->build_message($this->parts[$i]). "--$boundary";
    return$multipart.= "--\n";

    function send()
    $mime= "";
    $mime.= "From:".$this->from. "\n";
    $mime.=$this->headers. "\n";

    $this->add_attachment($this->body, "", "text/plain");
    $mime.= "MIME-Version:1.0\n".$this->build_multipart();
    return(mail($this->to,$this->subject, "",$mime));

    if (isset($BeenSubmitted)) {
    $num_errors = 0;
    if (! strlen($to) > 0) {
    echo "You must enter an e-mail address for the recipient.<br>";
    if (! strlen($from) > 0) {
    echo "You must enter your e-mail address.<br>";
    if (! strlen($subject) > 0) {
    echo "You must enter a subject for the e-mail.<br>";
    if (! strlen($message) > 0) {
    echo "You must enter some kind of message for the recipient.<br>";
    if (! $fp = @fopen($postcard,"r")) {
    echo "You must select a postcard from the left.<br>";

    if ($errors == 0) {
    $mail=new mime_mail();
    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">

    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

    blog comments powered by Disqus


    - Basic Ajax contact form
    - Random validation image
    - tinySendMail
    - SaferMail 0.7
    - Smtp Auth Email Script
    - Search Mime Email Structure
    - PHP Text / HTML Email with Attachments 2.1
    - Simple way to send mail wih one attached Doc...
    - Generic POP3 Class
    - PHP Text / HTML Email with Unlimited Attachm...
    - Another SendMail
    - email with attachment
    - Get Email Addresses from Strings
    - EmailCode
    - Email Validation - Gone Wild

    Developer Shed Affiliates


    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap