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;
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.
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.