Current location: Hot Scripts Forums » Programming Languages » PHP » MIME Attachment for Email Form


MIME Attachment for Email Form

Reply
  #1 (permalink)  
Old 12-10-03, 01:15 PM
phpuser phpuser is offline
New Member
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile MIME Attachment for Email Form

I am trying to have this form process a mime email attachment but when I run the script, I receive an email with a bunch of numbers and letters that are in place of the attachment. I also want to have the form check to make sure that only the file types of .jpg .png and .gif are accepted. Below is the script. Any help is greatly appreciated!

<?php
if ($FormSubmit) {
process_form(); # $FormSubmit is not blank
} else {
display_form(); # $FormSubmit is blank
} #end of if ($FormSubmit)
function display_form() { # Display form for user input
global $PHP_SELF;
?>
<table width="560" border="0" cellspacing="0" cellpadding="10">
<tr>
<td><img src="images/guestdj-bar.gif" alt="Guest DJ Submission" width="550" height="18" border="0"><br><br><font face="Verdana, Arial, Helvetica, sans-serif" size="1">If you would like to be featured as a guest DJ on this site, complete the form below. For website feedback or all other issues, you need to complete our <a href="<?php print("$PHP_SELF?id=1");?>" class="base" onMouseOver="window.status='Contact Form';return true" onMouseOut="window.status='';return true">Contact Form</a>. All fields marked with an asterisk (<font color="#FF0000">*</font>) are required.</font></td>
</tr>
</table>
<table width="560" border="0" cellspacing="10" cellpadding="0">
<tr>
<td>
<form name="Form2" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="FormSubmit" value="yes">
<input type="hidden" name="MAX_FILE_SIZE" value="50000">
<?
echo "<input type=hidden name=$REMOTE_ADDR value=$REMOTE_ADDR>";
echo "<input type=hidden name=$HTTP_USER_AGENT value=$HTTP_USER_AGENT>";
echo "<input type=hidden name=$HTTP_REFERER value=$HTTP_REFERER>";
?>
<table cellspacing=0 cellpadding=5 border=0 width="100%">
<tr bgcolor="#EEEEEE">
<td width="30%" nowrap><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">DJ Name<font color="#FF0000">***</font></font></td>
<td width="70%"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><input type="text" size="35" maxlength="256" name="DJName" class="input"></font></div></td>
</tr>
<tr bgcolor="#EEEEEE">
<td width="30%" nowrap><font face="Verdana, Arial, Helvetica, sans-serif" size="1">E-mail<font color="#FF0000">***</font></font></td>
<td width="70%"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><input type="text" size="35" maxlength="256" name="Email" class="input"></font></div></td>
</tr>
<tr bgcolor="#EEEEEE">
<td width="30%" nowrap><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Website URL</font></td>
<td width="70%"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><input type="text" size="35" maxlength="256" name="Website" value="http://" class="input"></font></div></td>
</tr>
<tr bgcolor="#EEEEEE">
<td width="30%" nowrap><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Music you spin<font color="#FF0000">***</font></font></td>
<td width="70%">
<div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
<select name="Select" class="input">
<option selected value="">&amp;middot;&amp;middot; SELECT &amp;middot;&amp;middot;</option>
<option value="Underground">Underground</option>
<option value="Techno">Techno</option>
<option value="Progressive">Progressive</option>
<option value="Trance">Trance</option>
<option value="Freestyle">Freestyle</option>
<option value="Drum &amp; Bass">Drum &amp; Bass</option>
<option value="Hard House">Hard House</option>
<option value="Garage">Garage</option>
<option value="Old School">Old School</option>
<option value="Hip-Hop">Hip-Hop</option>
<option value="R &amp; B">R &amp; B</option>
<option value="Other">Other</option>
</select>
</font></div>
</td>
</tr>
<tr bgcolor="#EEEEEE">
<td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">If you currenly have a mix on the web in Real Audio or Windows Media format, enter the exact address below where it's located so it can stream from the webpage we create for you.<br>(eg. www.yoursite.com/filename.ram) or (www.yoursite.com/filename.asx)</font></td>
</tr>
<tr bgcolor="#EEEEEE">
<td width="30%" nowrap><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Picture</font></td>
<td width="70%"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><input name="fileatt" type="file" class="input"></font></div></td>
</tr>
<tr bgcolor="#EEEEEE">
<td width="30%" nowrap><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Hosted Mix</font></td>
<td width="70%"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><input type="text" name="MixSet" size="35" value="http://" class="input"></font></div></td>
</tr>
<tr bgcolor="#EEEEEE">
<td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Enter DJ's biography below<font color="#FF0000">***</font><br><textarea name="Biography" wrap="physical" cols="63" rows="12" class="textarea"></textarea></font></td>
</tr>
</table>
<table cellspacing=0 cellpadding=5 border=0 width="100%">
<td align="right" height="100%" bgcolor="#EEEEEE"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><input type="button" value="submit" class="button" onMouseOut="this.style.backgroundColor='#FFFFFF'" onMouseOver="this.style.backgroundColor='#CCCCCC'" onClick="gdj()"> &amp;nbsp; <input type="reset" value="reset" class="button" onMouseOut="this.style.backgroundColor='#FFFFFF'" onMouseOver="this.style.backgroundColor='#CCCCCC'" ></font></td>
</table>
</form>
</td>
</tr>
</table>
<?php
} #end of function display_form()
function process_form() { # Process form after user clicks the submit button
global $DJName;
global $Email;
global $Website;
global $Select;
global $fileatt;
global $MixSet;
global $Biography;
global $REMOTE_ADDR;
global $HTTP_USER_AGENT;
global $HTTP_REFERER;
global $FormSubmit;

// Read POST request params into global vars
$message = $_POST['message'];

// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}

//Email comments
$SiteName = "SampleSite.com";
$SiteEmail = "sample@samplesite.com";
$subject = "$SiteName Auto-Reply";
$ThankYouMessage = "Form Confirmation";
$UserMessage = "$DJName,\n\n";
$UserMessage .= "You submitted the following information to $SiteName.\n\n";
$UserMessage .= "E-Mail: $Email\n";
$UserMessage .= "Website: $Website\n";
$UserMessage .= "Select: $Select\n";
$UserMessage .= "Picture: $fileatt_name\n";
$UserMessage .= "MixSet: $MixSet\n";
$UserMessage .= "DJ Biography: $Biography\n\n";
$UserMessage .= "For questions, please email us at: $SiteEmail\n\n";
$UserMessage .= "Thanks again for visiting us!\n\n";
$UserMessage .= "$SiteName\n";
mail("$Email", "$ThankYouMessage", "$UserMessage", "From: $SiteEmail");
$AdminMessage = "The following information was submitted:\n\n";
$AdminMessage .= "DJ Name: $DJName\n";
$AdminMessage .= "Email: $Email\n";
$AdminMessage .= "Website: $Website\n";
$AdminMessage .= "Select: $Select\n";
$AdminMessage .= "MixSet: $MixSet\n";
$AdminMessage .= "DJ Biography: $Biography\n\n";
$AdminMessage .= "Sender's IP: $REMOTE_ADDR\n";
$AdminMessage .= "$HTTP_USER_AGENT\n";
$AdminMessage .= "$HTTP_REFERER\n";
$AdminMessage .= "$message\n";
mail("$SiteEmail", "$SiteName - Guest DJ Submission", "$AdminMessage", "From: $SiteEmail") or die ("<br>&amp;nbsp;&amp;nbsp;<font face=Verdana, Arial, Helvetica, sans-serif size=2 color=FF0000><b>Error... Unable to submit your information at this time!</b><br><br>&amp;nbsp;&amp;nbsp;<font size=1>Please try again later.</font></font>");
?>
<table width="560" border="0" cellspacing="0" cellpadding="10">
<tr>
<td><img src="images/thanks-bar.gif" alt="Thank You" width="550" height="18" border="0">
</tr>
</table>
<table width="560" border="0" cellspacing="10" cellpadding="0">
<tr bgcolor="#EEEEEE">
<td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Thank You <?php echo "$DJName"; ?>,<br><br>You submitted the following data...</font></td></tr>
<td>
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr bgcolor="#EEEEEE">
<td width="25%"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">E-Mail:</font></td>
<td width="75%"><font face="Verdana, Arial, Helvetica, sans-serif" color="#0000FF" size="1"><?php echo "$Email"; ?></font></td>
<tr bgcolor="#EEEEEE">
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Website:</font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" color="#0000FF" size="1"><?php echo "$Website"; ?>&amp;nbsp;</font></td>
</tr>
<tr bgcolor="#EEEEEE">
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Mix Type:</font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" color="#0000FF" size="1"><?php echo "$Select"; ?>&amp;nbsp;</font></td>
</tr>
<tr bgcolor="#EEEEEE">
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Picture:</font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" color="#0000FF" size="1"><?php echo "$fileatt_name"; ?>&amp;nbsp;</font></td>
</tr>
<tr bgcolor="#EEEEEE">
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Hosted Mix URL:</font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" color="#0000FF" size="1"><?php echo "$MixSet"; ?>&amp;nbsp;</font></td>
</tr>
<tr bgcolor="#EEEEEE">
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">DJ Biography:</font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" color="#0000FF" size="1"><?php echo "$Biography"; ?></font></td>
</tr>
<tr bgcolor="#EEEEEE">
<td colspan="2"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">You will receive an email confirming what information was sent.</font></td>
</tr>
<tr bgcolor="#EEEEEE">
<td colspan="2"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Your IP address is: <font color="#0000FF"><?php echo "$REMOTE_ADDR"; ?></font></font></td>
</tr>
</table>
</tr>
</table>
<?php
} #end of function process_form()
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 03:06 AM
question on form and submit TxRanger JavaScript 2 11-03-03 11:28 AM
SQL database registration form help vinhkhuong PHP 3 10-10-03 03:49 AM
asp: URGENT! need to change code to create new form per id seala ASP 2 09-09-03 09:54 PM
close form sasi ASP 4 08-26-03 03:51 AM


All times are GMT -5. The time now is 07:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.