Sky Captain
10-19-2004, 12:10 PM
Hey there. Some time ago I started a thread over in the Javascript forum looking for a way for visitors to my website to send me data and images using an email form. I got some great PHP info from Pittiman:
http://www.webdeveloper.com/forum/showthread.php?threadid=29742&perpage=15&pagenumber=1
I've got new problems, but rather than add to that thread, I'm starting a new one here in the appropriate forum.
So now I'm getting around to putting this site online. The images come through fine on email. But I want a whole bunch of text, too. Name, address, phone, email, etc.
But when I receive test emails, they contain the image attachment and the "message" text area, nothing else. How do I get the other text areas to show up? I've tried altering the PHP code, but it never comes out the way I like.
My email form (HTML) looks like this:
<form action="buycustomcode.php" method="POST" enctype="multipart/form-data" name="imgForm" onSubmit="return formCheck()">
<input type="hidden" name="subject" value="CUSTOM CARD ORDER with IMAGE">
<p>
<h4>Contact Information</h4>
<P>
<pre>
First Name <INPUT NAME="FIRST_NAME" value="" SIZE="15" TYPE="text"> Last Name <INPUT NAME="LAST_NAME" value="" SIZE="15" TYPE="text">
Address <INPUT NAME="ADDRESS" value="" SIZE="40" TYPE="text">
City <INPUT NAME="CITY" value="" SIZE="15" TYPE="text"> State <INPUT NAME="STATE" value="" SIZE="2" TYPE="text"> Zip Code <INPUT NAME="ZIP" value="" SIZE="5" TYPE="text">
Phone Number (Optional) <INPUT NAME="PHONE" value="" SIZE="15" TYPE="text">
Email (Mandatory) <input type="text" name="EMAILaddress" value="" SIZE="40">
</pre>
<FONT SIZE="-1" FACE="VERDANA, ARIAL, HELVETICA">
<P>
Please pick out the type of card for your template.
<P>
<table width=100%>
<tr>
<td align=center>
<img src="images/customezX250-143.jpg" width=250 height=143 border=1 alt="EZ X"><br>Choose EZ X here: <input type="radio" name="custom_choice" value="EZ X" CHECKED>
</td>
<td align=center>
<img src="images/customY250-143.jpg" width=250 height=143 border=1 alt="Y"><br>Choose Y here: <input type="radio" name="custom_choice" value="Y">
</td>
</tr>
<tr><td colspan=2> </td></tr>
<tr>
<td align=center>
<img src="images/customezZ250-143.jpg" width=250 height=143 border=1 alt="EZ Z"><br>Choose EZ Z here: <input type="radio" name="custom_choice" value="EZ Z">
</td>
<td align=center>
<img src="images/customZZ250-143.jpg" width=250 height=143 border=1 alt="ZZ"><br>Choose ZZ here: <input type="radio" name="custom_choice" value="ZZ">
</td>
</tr>
</table>
<P>
Provide your personalized text here:
<P ALIGN=CENTER>
<textarea cols="50" rows="5" name="message"></textarea><br>
</p>
Please select an image from your hard disk:<br>
<P ALIGN=CENTER>
<input type="file" name="attachedImg"><br><br>
<p align=center>
<input type="submit">
<input type="reset">
</p>
</form>
It then forwards the user to the PHP code page (buycustomcode.php) here:
<?php
$to= 'test@test.com';//your email address has to go here and
$from= 'test@test.com';//here (second time to be sure, that mail will arrive
$maxSize=102400;//allowed file size in bytes
/*If you want to add more filetypes here, you will need to know the mime type; see this sample for a few types:
$extArray = array('image/gif','image/bmp','image/pjpeg','image/x-png');*/
$extArray = array('image/pjpeg');//valid type now
$from2= $_POST['from2'];
$subject = $_POST['subject'];
$message = stripslashes($_POST['message']);
$attachedImg= $_FILES['attachedImg']['tmp_name'];
$attachedImg_type = $_FILES['attachedImg']['type'];
$attachedImg_name = $_FILES['attachedImg']['name'];
if (filesize($attachedImg)>$maxSize){
echo 'The file is bigger than allowed: '.filesize($attachedImg). ' bytes;<br>';
echo 'The allowed maximum size is: '.$maxSize. ' bytes.<br>';
echo 'Click <a href="buycustom4.html" title=" try again ">here</a> to get back to the form...';
}
if ($attachedImg_type!='image/x-png'&&!in_array($attachedImg_type,$extArray)){
echo $attachedImg_type.' is not permitted!<br>';
echo 'Click <a href="buycustom4.html" title=" try again ">here</a> to get back to the form...';
}
if (filesize($attachedImg)<=$maxSize&&in_array($attachedImg_type,$extArray)){
$headers = "From: $from";
if (is_uploaded_file($attachedImg)) {
$file = fopen($attachedImg,'rb');
$data = fread($file,filesize($attachedImg));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message2 = "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" .
$message2 . $message."\n\n";
$data = chunk_split(base64_encode($data));
$message2 .= "--{$mime_boundary}\n" .
"Content-Type: {$attachedImg_type};\n" .
" name=\"{$attachedImg_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$ok = @mail($to, $subject, $message2, $headers);
if ($ok) {
echo "<p>Order sent successfully! Please wait for Paypal instructions...</p><br>";
}
else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
}
?>
Any help would be appreciated!
http://www.webdeveloper.com/forum/showthread.php?threadid=29742&perpage=15&pagenumber=1
I've got new problems, but rather than add to that thread, I'm starting a new one here in the appropriate forum.
So now I'm getting around to putting this site online. The images come through fine on email. But I want a whole bunch of text, too. Name, address, phone, email, etc.
But when I receive test emails, they contain the image attachment and the "message" text area, nothing else. How do I get the other text areas to show up? I've tried altering the PHP code, but it never comes out the way I like.
My email form (HTML) looks like this:
<form action="buycustomcode.php" method="POST" enctype="multipart/form-data" name="imgForm" onSubmit="return formCheck()">
<input type="hidden" name="subject" value="CUSTOM CARD ORDER with IMAGE">
<p>
<h4>Contact Information</h4>
<P>
<pre>
First Name <INPUT NAME="FIRST_NAME" value="" SIZE="15" TYPE="text"> Last Name <INPUT NAME="LAST_NAME" value="" SIZE="15" TYPE="text">
Address <INPUT NAME="ADDRESS" value="" SIZE="40" TYPE="text">
City <INPUT NAME="CITY" value="" SIZE="15" TYPE="text"> State <INPUT NAME="STATE" value="" SIZE="2" TYPE="text"> Zip Code <INPUT NAME="ZIP" value="" SIZE="5" TYPE="text">
Phone Number (Optional) <INPUT NAME="PHONE" value="" SIZE="15" TYPE="text">
Email (Mandatory) <input type="text" name="EMAILaddress" value="" SIZE="40">
</pre>
<FONT SIZE="-1" FACE="VERDANA, ARIAL, HELVETICA">
<P>
Please pick out the type of card for your template.
<P>
<table width=100%>
<tr>
<td align=center>
<img src="images/customezX250-143.jpg" width=250 height=143 border=1 alt="EZ X"><br>Choose EZ X here: <input type="radio" name="custom_choice" value="EZ X" CHECKED>
</td>
<td align=center>
<img src="images/customY250-143.jpg" width=250 height=143 border=1 alt="Y"><br>Choose Y here: <input type="radio" name="custom_choice" value="Y">
</td>
</tr>
<tr><td colspan=2> </td></tr>
<tr>
<td align=center>
<img src="images/customezZ250-143.jpg" width=250 height=143 border=1 alt="EZ Z"><br>Choose EZ Z here: <input type="radio" name="custom_choice" value="EZ Z">
</td>
<td align=center>
<img src="images/customZZ250-143.jpg" width=250 height=143 border=1 alt="ZZ"><br>Choose ZZ here: <input type="radio" name="custom_choice" value="ZZ">
</td>
</tr>
</table>
<P>
Provide your personalized text here:
<P ALIGN=CENTER>
<textarea cols="50" rows="5" name="message"></textarea><br>
</p>
Please select an image from your hard disk:<br>
<P ALIGN=CENTER>
<input type="file" name="attachedImg"><br><br>
<p align=center>
<input type="submit">
<input type="reset">
</p>
</form>
It then forwards the user to the PHP code page (buycustomcode.php) here:
<?php
$to= 'test@test.com';//your email address has to go here and
$from= 'test@test.com';//here (second time to be sure, that mail will arrive
$maxSize=102400;//allowed file size in bytes
/*If you want to add more filetypes here, you will need to know the mime type; see this sample for a few types:
$extArray = array('image/gif','image/bmp','image/pjpeg','image/x-png');*/
$extArray = array('image/pjpeg');//valid type now
$from2= $_POST['from2'];
$subject = $_POST['subject'];
$message = stripslashes($_POST['message']);
$attachedImg= $_FILES['attachedImg']['tmp_name'];
$attachedImg_type = $_FILES['attachedImg']['type'];
$attachedImg_name = $_FILES['attachedImg']['name'];
if (filesize($attachedImg)>$maxSize){
echo 'The file is bigger than allowed: '.filesize($attachedImg). ' bytes;<br>';
echo 'The allowed maximum size is: '.$maxSize. ' bytes.<br>';
echo 'Click <a href="buycustom4.html" title=" try again ">here</a> to get back to the form...';
}
if ($attachedImg_type!='image/x-png'&&!in_array($attachedImg_type,$extArray)){
echo $attachedImg_type.' is not permitted!<br>';
echo 'Click <a href="buycustom4.html" title=" try again ">here</a> to get back to the form...';
}
if (filesize($attachedImg)<=$maxSize&&in_array($attachedImg_type,$extArray)){
$headers = "From: $from";
if (is_uploaded_file($attachedImg)) {
$file = fopen($attachedImg,'rb');
$data = fread($file,filesize($attachedImg));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message2 = "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" .
$message2 . $message."\n\n";
$data = chunk_split(base64_encode($data));
$message2 .= "--{$mime_boundary}\n" .
"Content-Type: {$attachedImg_type};\n" .
" name=\"{$attachedImg_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$ok = @mail($to, $subject, $message2, $headers);
if ($ok) {
echo "<p>Order sent successfully! Please wait for Paypal instructions...</p><br>";
}
else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
}
?>
Any help would be appreciated!