I have a web form that automatically sends an email to dealer if you check their check box...i would like to have a photo attached to the email as well...
Is this possible, if yes, how?
any help would be greatly appreciated.
Thanks
attaching a photo to email
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
eyespike1,
Yes you can....but is the image on the server? or does the person have to upload the file
what would happen is that you will have to do what is called a multipart email (cant remeber the exact term) which encodes your email to allow images, files and text in one...you cant send it just so....
usually you can send it as and atachment or embedded in the email itself....i had a post about this in which i posted some code i used to do it...search under my name using the same mail() query you shud be able to find some code to use there as well as some tips on what to do
Kendall
Yes you can....but is the image on the server? or does the person have to upload the file
what would happen is that you will have to do what is called a multipart email (cant remeber the exact term) which encodes your email to allow images, files and text in one...you cant send it just so....
usually you can send it as and atachment or embedded in the email itself....i had a post about this in which i posted some code i used to do it...search under my name using the same mail() query you shud be able to find some code to use there as well as some tips on what to do
Kendall
can't attach jpeg images
Kendall, I ran across this code which works great for gif's...but it crashes on the jpeg image upload...any ideas?
<?php
// Check to see if the form has been posted
if (isset($_POST['SendFile']))
{
// Set the Array of acceptable FileTypes
$FileTypes=array("image/jpeg", "image/gif");
// Check to ensure the uploaded file is of correct type
if (in_array($_FILES['UPLDoc']['type'],$FileTypes))
{
// Set the upload directory
$UploadDir = 'upload/';
// Move the file
move_uploaded_file($_FILES['UPLDoc']['tmp_name'], $UploadDir . $_FILES['UPLDoc']['name']);
// Open the file and read the contents into a string
$FileName=$UploadDir.$_FILES['UPLDoc']['name'];
$FilePointer=fopen($FileName, "r");
$File=fread($FilePointer, filesize ($FileName));
fclose($FilePointer);
// Encode and chunk split the data for the e-mail
$File=chunk_split(base64_encode($File));
// Set the receiving e-mail address
$EMail="email@email.com";
// Set the headers of the e-mail
$Headers="From: someone@domain.com\n";
$Headers.="Reply-To: someone@domain.com\n";
$Headers.="MIME-Version: 1.0\n";
$Headers.="Content-Type: multipart/mixed; boundary=\"MIME_BOUNDRY\"\n";
$Headers.="X-Sender: someone@domain.com\n";
$Headers.="X-Mailer: PHP4\n";
$Headers.="X-Priority: 3\n";
$Headers.="Return-Path: someone@domain.com\n";
$Headers.="This is a multi-part Contentin MIME format.\n";
// Set the Content of the e-mail
$Content="--MIME_BOUNDRY\n";
$Content.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$Content.="Content-Transfer-Encoding: quoted-printable\n";
$Content.="\n";
$Content.="".$_POST['Name']." just sent you the attached file for review.\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY\n";
$Content.="Content-Type: ".$_FILES['UPLDoc']['type']."; name=\"".$_FILES['UPLDoc']['name']."\"\n";
$Content.="Content-disposition: attachment\n";
$Content.="Content-Transfer-Encoding: base64\n";
$Content.="\n";
$Content.="$File\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY--\n";
// Set the Subject of the e-mail
$Subject="New file to review";
// Send the e-mail
mail($EMail,$Subject,$Content,$Headers);
}else
{
echo "You cannot upload this type of file";
}
}
?>
<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>">
<INPUT TYPE="HIDDEN" NAME="SendFile" VALUE="Send File">
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="100000">
Your Name: <INPUT TYPE="TEXT" NAME="Name"><BR>
Select Document: <INPUT TYPE="FILE" NAME="UPLDoc"><BR>
<INPUT TYPE="SUBMIT" NAME="SendFile" VALUE="Send File">
</FORM>
<?php
// Check to see if the form has been posted
if (isset($_POST['SendFile']))
{
// Set the Array of acceptable FileTypes
$FileTypes=array("image/jpeg", "image/gif");
// Check to ensure the uploaded file is of correct type
if (in_array($_FILES['UPLDoc']['type'],$FileTypes))
{
// Set the upload directory
$UploadDir = 'upload/';
// Move the file
move_uploaded_file($_FILES['UPLDoc']['tmp_name'], $UploadDir . $_FILES['UPLDoc']['name']);
// Open the file and read the contents into a string
$FileName=$UploadDir.$_FILES['UPLDoc']['name'];
$FilePointer=fopen($FileName, "r");
$File=fread($FilePointer, filesize ($FileName));
fclose($FilePointer);
// Encode and chunk split the data for the e-mail
$File=chunk_split(base64_encode($File));
// Set the receiving e-mail address
$EMail="email@email.com";
// Set the headers of the e-mail
$Headers="From: someone@domain.com\n";
$Headers.="Reply-To: someone@domain.com\n";
$Headers.="MIME-Version: 1.0\n";
$Headers.="Content-Type: multipart/mixed; boundary=\"MIME_BOUNDRY\"\n";
$Headers.="X-Sender: someone@domain.com\n";
$Headers.="X-Mailer: PHP4\n";
$Headers.="X-Priority: 3\n";
$Headers.="Return-Path: someone@domain.com\n";
$Headers.="This is a multi-part Contentin MIME format.\n";
// Set the Content of the e-mail
$Content="--MIME_BOUNDRY\n";
$Content.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$Content.="Content-Transfer-Encoding: quoted-printable\n";
$Content.="\n";
$Content.="".$_POST['Name']." just sent you the attached file for review.\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY\n";
$Content.="Content-Type: ".$_FILES['UPLDoc']['type']."; name=\"".$_FILES['UPLDoc']['name']."\"\n";
$Content.="Content-disposition: attachment\n";
$Content.="Content-Transfer-Encoding: base64\n";
$Content.="\n";
$Content.="$File\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY--\n";
// Set the Subject of the e-mail
$Subject="New file to review";
// Send the e-mail
mail($EMail,$Subject,$Content,$Headers);
}else
{
echo "You cannot upload this type of file";
}
}
?>
<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>">
<INPUT TYPE="HIDDEN" NAME="SendFile" VALUE="Send File">
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="100000">
Your Name: <INPUT TYPE="TEXT" NAME="Name"><BR>
Select Document: <INPUT TYPE="FILE" NAME="UPLDoc"><BR>
<INPUT TYPE="SUBMIT" NAME="SendFile" VALUE="Send File">
</FORM>
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
eyesspike,
uhmmm....i see you are "attaching the file" i think you need to specifiy the MIME TYPE. Im surprise the "gif" part is working wihtout specifyinh a MIME CONTENT TYPE.
Kendall
I think i posted a script similar to this which works...see if you can find it using the mail() search term or something.
uhmmm....i see you are "attaching the file" i think you need to specifiy the MIME TYPE. Im surprise the "gif" part is working wihtout specifyinh a MIME CONTENT TYPE.
Kendall
I think i posted a script similar to this which works...see if you can find it using the mail() search term or something.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA