I'm writing a mailform i php for placeing orders, and sense they have to get send a picture to me for the order to work properly, I'd like to be able to attach the file in the formmail. How shuld I do this? I have seen some different sulutions but non that I've complety understand.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I would also suggest php_mailer http://sourceforge.net/project/showfiles.php?group_id=26031
Has all of the options you could ever want and lets you build custom length forms without "TOO" much pain
There are also a bunch of tutorials and would gladly send along an example of a project I did recently if you want
You need to set the right mail-headers, and then attach the file by encoding it to whatever form you have declared in the header, like in this snippet:
All you need to do here, is read the file, and encode it (to base64 in this case)
first you'll need a boundary, like a rule to tell where one part stops, and the other begins
then set the headers right, to support attachement
then build up your message
and then... sent the message using mail ;-)
$sl="select max(id)AS maxid from photos"; $res=mysql_query($sl); $rowl=@mysql_fetch_array($res);
$adid=$rowl['maxid']; $filedir="/photo_gallery/"; $file1=$filedir."img".$adid.$_FILES['myfile']['name'];
//echo $file1; @move_uploaded_file($_FILES['myfile']['tmp_name'],$file1);
$upd="update photos set photo='".$file1."',Added_date=now() where id=$adid";
//echo $upd; mysql_query($upd);
@unlink($file1);