php向指定文件发送消息,PHP-将文件发送给用户
白衣非少年
好的,所以我不是PHP的專家,我只能歸功于將其他幾段PHP放在一起以實(shí)現(xiàn)我需要的功能,我認(rèn)為最好將這個(gè)解決方案發(fā)布在一些要求同樣的問題,但我自己無法工作。似乎在任何地方都沒有解決方案,所以在這里。它對(duì)我有用...好吧,首先我創(chuàng)建了PDF表單,并添加了一個(gè)按鈕,然后提交表單。在此提交表單的操作中,我告訴它以PDF格式發(fā)送完整的文檔。然后,我給它提供了指向php頁(yè)面的URL鏈接,例如mail_my_form.php。然后,我創(chuàng)建了一個(gè)php表單,并將其命名為與上面相同。mail_my_form.php的最后一件事是在根目錄中創(chuàng)建一個(gè)名為pdfs的文件夾。此php代碼的位置。(因此,如果將php放在名為email的文件夾中,然后在email文件夾中,您需要另一個(gè)名為pdfs的文件夾)現(xiàn)在,此腳本的作用是:將PDF保存為文件名pdfs。然后,它將文件附加到電子郵件并發(fā)送。然后從文件夾pdfs中刪除該文件以節(jié)省空間。(如果需要,您也可以刪除功能以將表單保存在FTP上。這里是。<?php ?
$fileatt?=?date("d-m-Y-His")?.?".pdf";??//?Creates?unique?PDF?name?from?the?date?copy('php://input',"pdfs/".$fileatt);?//?Copies?the?pdf?form?data?to?a?folder?named?pdfs?$fileatt?=?"pdfs/".$fileatt;?//?Path?to?the?file?gives?the?pdfs?folder?plus?the?unique?file?name?we?just?assigned$fileatt_type?=?"application/pdf";?//?File?Type?$fileatt_name?=?"Application?Form_".$fileatt.".pdf";?//?Filename?that?will?be?used?for?the?file?as?the?attachment?when?it?is?sent$email_from?=?"mywebsite";?//?Who?the?email?is?from?$email_subject?=?"Completed?online?Applications";?//?The?Subject?of?the?email?$email_message?=?"Please?find?a?recent?online?application?attached.
";
?$email_message?.=?"Any?problems?please?email?me...
";?//?Message?that?the?email?has?in?it?$email_to?=?"youremail@yourserver.com";?//?Who?the?email?is?to?$headers?=?"From:?".$email_from;//no?need?to?change?anything?else?under?this?point$file?=?fopen($fileatt,'rb');?$data?=?fread($file,filesize($fileatt));?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}\"";?$email_message?.=?"This?is?a?multi-part?message?in?MIME?format.\n\n"?.?"--{$mime_boundary}\n"?.?"Content-Type:text/html;?charset=\"iso-8859-1\"\n"?.?"Content-Transfer-Encoding:?7bit\n\n"?.?$email_message?.=?"\n\n";?$data?=?chunk_split(base64_encode($data));?$email_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";?$ok?=?@mail($email_to,?$email_subject,?$email_message,?$headers);?if($ok)?{?unlink($fileatt);?//NOW?WE?DELETE?THE?FILE?FROM?THE?FOLDER?pdfs?Header("Location:?nextpage.php");?//where?do?we?go?once?the?form?has?been?submitted.}?else?{?die("Sorry?but?the?email?could?not?be?sent.?Please?go?back?and?try?again!");?}??>希望對(duì)您有所幫助。理查德·威廉姆斯
總結(jié)
以上是生活随笔為你收集整理的php向指定文件发送消息,PHP-将文件发送给用户的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql存json将utf8编码 去掉
- 下一篇: oracle ogg双向通步,使用ogg