简体   繁体   English

PHP Form通过电子邮件发送结果。 我需要捕获表单中的上传文件

[英]PHP Form Emailed results. I need to capture the upload file in the form

I have a form that emails the results with each submit via a PHP script. 我有一个表单,通过PHP脚本通过电子邮件将结果与每个提交一起通过电子邮件发送。

I'm using an ajax script to upload files to my server in the form. 我正在使用ajax脚本将文件上传到表单中的服务器。

Is it possible to notify me with a YEs or NO if a file has been uploaded? 如果上传了文件,是否可以通过“是”或“否”通知我?

Is there any waY to attach the file to the form? 是否有将文件附加到表单的方法?

Any illustrations? 有插图吗?

I'm using ajax and jquery. 我正在使用ajax和jquery。

Erik 埃里克

    <?php
    $prefix = 'LPFQ';
    $uniqid = $prefix . uniqid();
    $QuoteID = strtoupper($uniqid); 
    $Email      = $_REQUEST['Email'];
    $Name       = $_REQUEST['Name'];
    $Company    = $_REQUEST['Company'];
    $Telephone  = $_REQUEST['Telephone'];
    $Message    = stripslashes($_REQUEST['Message']);
    $Industry       = $_REQUEST['Industry'];
    $ProjectName     = stripslashes($_REQUEST['ProjectName']);
    $Combination     = $_REQUEST['Combination'];
    $DateExpectDelivery  = $_REQUEST['DateExpectDelivery'];
    $UploadFiles     = $_REQUEST['UploadFiles'];
    $Quantity1   = $_REQUEST['Quantity1'];
    $Quantity2   = $_REQUEST['Quantity2'];
    $Quantity3   = $_REQUEST['Quantity3'];
    $Quantity4   = $_REQUEST['Quantity4'];
    $CartonSizeLength    = $_REQUEST['CartonSizeLength'];
    $CartonSizeWidth     = $_REQUEST['CartonSizeWidth'];
    $CartonSizeHeight    = $_REQUEST['CartonSizeHeight'];
    $FlatSizeWidth   = $_REQUEST['FlatSizeWidth'];
    $FlatSizeHeight  = $_REQUEST['FlatSizeHeight'];
    $CartonStyle     = $_REQUEST['CartonStyle'];
    $BoardCaliper    = $_REQUEST['BoardCaliper'];
    $BoardDescription    = $_REQUEST['BoardDescription'];
    $ColorsSpot  = $_REQUEST['ColorsSpot'];
    $ColorsProcess   = $_REQUEST['ColorsProcess'];
    $ColorsTotal     = $_REQUEST['ColorsTotal'];
    $CoatFinish  = $_REQUEST['CoatFinish'];
    $CoatFinish2     = $_REQUEST['CoatFinish2'];
    $DieCutHolesNum  = $_REQUEST['DieCutHolesNum'];
    $DieCutHolesStrip    = !empty($_REQUEST['DieCutHolesStrip']) ? 'Yes' :       'No';
    $DieCutHolesPerf     = !empty($_REQUEST['DieCutHolesPerf']) ? 'Yes' : 'No';
    $GlueAreasNum    = $_REQUEST['GlueAreasNum'];
    $GlueAreasCheck  = !empty($_REQUEST['GlueAreasCheck']) ? 'Yes' : 'No';
    $GlueAreasSensor     = !empty($_REQUEST['GlueAreasSensor']) ? 'Yes' : 'No';
    $GlueAreasRFID   = !empty($_REQUEST['GlueAreasRFID']) ? 'Yes' : 'No';
    $WindowPatchWidth    = $_REQUEST['WindowPatchWidth'];
    $WindowPatchHeight   = $_REQUEST['WindowPatchHeight'];
    $SpecialtyFoil   = !empty($_REQUEST['SpecialtyFoil']) ? 'Yes' : 'No';
    $SpecialtyBoss   = !empty($_REQUEST['SpecialtyBoss']) ? 'Yes' : 'No';
    $SpecialtyBraille    = !empty($_REQUEST['SpecialtyBraille']) ? 'Yes' : 'No';
    $SpecialtyInserts    = !empty($_REQUEST['SpecialtyInserts']) ? 'Yes' : 'No';
    $ShipToZip   = $_REQUEST['ShipToZip'];
    $InnerDivider    = !empty($_REQUEST['InnerDivider']) ? 'Yes' : 'No';        

    $MyTimezone = date_default_timezone_set('America/Los_Angeles');

$Body = "\\n" ." \\n" ."\\n" ." $ Body =“ \\ n”。“ \\ n”。“ \\ n”。“
\\n" \\ n“

                                ."<span style=\"line-height:10px;\">&nbsp;</span>\n"
                                ."<table id=\"hor-zebra\">\n"
                                ."<tr><td class=\"label\"><strong>Quote ID:</strong></td><td>".$QuoteID."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Name:</strong></td><td>".$Name."</td></tr>\n"
                                ."<tr><td><strong>Company:</strong></td><td>".$Company."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Telephone:</strong></td><td>".$Telephone."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Email:</strong></td><td>".$Email."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Industry:</strong></td><td>".$Industry."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Combination:</strong></td><td>".$Combination."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Additional Notes:</strong></td><td>".$Message."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Upload Files:</strong></td><td>".$UploadFiles."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Project Name:</strong></td><td>".$ProjectName."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Quantity 1:</strong></td><td>".$Quantity1."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Quantity 2:</strong></td><td>".$Quantity2."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Quantity 3:</strong></td><td>".$Quantity3."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Quantity 4:</strong></td><td>".$Quantity4."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Carton Size Length:</strong></td><td>".$CartonSizeLength."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Carton Size Width:</strong></td><td>".$CartonSizeWidth."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Carton Size Height:</strong></td><td>".$CartonSizeHeight."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Flat Size Width:</strong></td><td>".$FlatSizeWidth."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Flat Size Height:</strong></td><td>".$FlatSizeHeight."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Carton Style:</strong></td><td>".$CartonStyle."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Inner Divider:</strong></td><td>".$InnerDivider."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Board Caliper:</strong></td><td>".$BoardCaliper."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Board Description:</strong></td><td>".$BoardDescription."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Colors Spot:</strong></td><td>".$ColorsSpot."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Colors Process:</strong></td><td>".$ColorsProcess."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Colors Total:</strong></td><td>".$ColorsTotal."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Coat Finish:</strong></td><td>".$CoatFinish."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Coat Finish 2:</strong></td><td>".$CoatFinish2."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Die Cut Holes Num:</strong></td><td>".$DieCutHolesNum."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Die Cut Holes Strip:</strong></td><td>".$DieCutHolesStrip."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Die Cut Holes Perf:</strong></td><td>".$DieCutHolesPerf."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Glue Areas Num:</strong></td><td>".$GlueAreasNum."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Glue Areas Check:</strong></td><td>".$GlueAreasCheck."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Glue Areas Sensor:</strong></td><td>".$GlueAreasSensor."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Glue Areas RFID:</strong></td><td>".$GlueAreasRFID."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Window Patch Width:</strong></td><td>".$WindowPatchWidth."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Window Patch Height:</strong></td><td>".$WindowPatchHeight."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Specialty Foil:</strong></td><td>".$SpecialtyFoil."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Specialty Boss:</strong></td><td>".$SpecialtyBoss."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Specialty Braille:</strong></td><td>".$SpecialtyBraille."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Specialty Inserts:</strong></td><td>".$SpecialtyInserts."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Ship To Zip:</strong></td><td>".$ShipToZip."</td></tr>\n"
                                ."<tr><td class=\"label\"><strong>Date Expect Delivery:</strong></td><td>".$DateExpectDelivery."</td></tr>\n"
                                ."<tr class=\"odd\"><td class=\"label\"><strong>Date of Submission:</strong></td><td>".date("Y-m-d H:i A e")."</td></tr>\n"
                                ."</table>\n"
                                ."<span style=\"line-height:30px;\">&nbsp;</span>\n"
                                ."</body></html>\n";

// Mail 1 //邮件1

// multiple recipients $To = 'LOGIC Estimating Team '; //多个收件人$ To ='LOGIC Estimating Team';

// subject $Subject = 'Logic Pakaging Fast Quote'; // subject $ Subject ='逻辑包装快速报价';

// To send HTML mail, the Content-type header must be set $Headers = 'MIME-Version: 1.0' . //要发送HTML邮件,必须将Content-type标头设置为$ Headers ='MIME-Version:1.0'。 "\\r\\n"; “ \\ r \\ n”; $Headers .= 'Content-type: text/html; $ Headers。='内容类型:text / html; charset=iso-8859-1' . charset = iso-8859-1'。 "\\r\\n"; “ \\ r \\ n”;

// Additional headers $Headers .= 'From: LOGIC Estimating Team ' . //附加标头$ Headers。='来自:LOGIC估算团队'。 "\\r\\n"; “ \\ r \\ n”; $Headers .= 'Cc:' . $ Headers。='抄送:'。 "\\r\\n"; “ \\ r \\ n”; $Headers .= 'Bcc:' . $ Headers。='密件抄送:'。 "\\r\\n"; “ \\ r \\ n”;

// Mail it mail($To, $Subject, $Body, $Headers); //寄出邮件($ To,$ Subject,$ Body,$ Headers);

// Mail 2 //邮件2

$Body = "\\n" ." \\n" ."\\n" ." $ Body =“ \\ n”。“ \\ n”。“ \\ n”。“
\\n" ."We received your quote request successfully. \\ n“。”我们已成功收到您的报价请求。

\\n" ." \\ n“。” \\n" ."\\n" ." \\ n“。” \\ n“。” Quote ID: ".$QuoteID."\\n" ." 引用ID: “。$ QuoteID。” \\ n“。 Name: ".$Name."\\n" ." 名称: “。$ Name。” \\ n“。” Company: ".$Company."\\n" ." 公司: “。$ Company。” \\ n“。” Telephone: ".$Telephone."\\n" ." 电话: “。$ Telephone。” \\ n“。” Email: ".$Email."\\n" ."\\n" ." 电子邮件: “。$ Email。” \\ n“。” \\ n“。” \\n" ."\\n"; \\ n“。” \\ n“;

// multiple recipients $To = $Email; //多个收件人$ To = $ Email;

// subject $Subject = 'Logic Pakaging Fast Quote'; // subject $ Subject ='逻辑包装快速报价';

// To send HTML mail, the Content-type header must be set $Headers = 'MIME-Version: 1.0' . //要发送HTML邮件,必须将Content-type标头设置为$ Headers ='MIME-Version:1.0'。 "\\r\\n"; “ \\ r \\ n”; $Headers .= 'Content-type: text/html; $ Headers。='内容类型:text / html; charset=iso-8859-1' . charset = iso-8859-1'。 "\\r\\n"; “ \\ r \\ n”;

// Additional headers $Headers .= 'From: LOGIC Estimating Team ' . //附加标头$ Headers。='来自:LOGIC估算团队'。 "\\r\\n"; “ \\ r \\ n”; $Headers .= 'Cc:' . $ Headers。='抄送:'。 "\\r\\n"; “ \\ r \\ n”; $Headers .= 'Bcc:' . $ Headers。='密件抄送:'。 "\\r\\n"; “ \\ r \\ n”;

// Mail it mail($To, $Subject, $Body, $Headers); //寄出邮件($ To,$ Subject,$ Body,$ Headers);

header("Location: http://www.logicpkg.com/quote_confirm.php?Name= " . urlencode($Name)); header(“ Location: http : //www.logicpkg.com/quote_confirm.php? Name = ”。urlencode($ Name)); ?> ?>

That's hard to answer without being more specific and/or posting your code. 如果不更具体和/或发布您的代码,很难回答。 I mean, it is certainly possible for your uploader script to either signal (say, via a session) or store (say, via a database) an indicator that a file was uploaded, and your email script can do something (like attaching the file) with that information. 我的意思是,您的上传者脚本肯定有可能发信号(例如,通过会话)或存储(例如,通过数据库)指示文件已上传的指示符,并且电子邮件脚本可以执行某些操作(例如附加文件) )的信息。 You can also attach files to emails (I'm assuming that's what you meant) as MIME attachments. 您还可以将文件作为MIME附件附加到电子邮件中(我假设这就是您的意思)。 Google 'MIME_mail'. Google“ MIME_mail”。

If I didn't answer your question, please describe the desired outcome in more detail. 如果我没有回答您的问题,请更详细地描述所需的结果。

Hard to say without seeing the code or knowing the system. 不看代码或不了解系统就很难说。 But I assume the ajax uploading, and the form posting which sends the email, are separated. 但是我假设ajax上传与发送电子邮件的表单发布是分开的。 So one really has no idea what happened with the other. 因此,一个人真的不知道另一个人怎么了。

What you could do, is give the file a dynamically generated key, so its name will be something like /uploads/abc123_thefile.zip . 您可以做的是为文件提供一个动态生成的密钥,因此其名称应类似于/uploads/abc123_thefile.zip Then on the form that gets posted you'll have an id field, which will be the same as what was tacked onto the file name: 然后在发布的表单上,您将拥有一个id字段,该字段与添加到文件名上的ID字段相同:

<input type=hidden name=key value='abc123'>

Then when you get the $_POST data, in your php script, you could check the uploads directory for a file that starts with the $_POST['key'] data. 然后,当您在PHP脚本中获取$ _POST数据时,可以检查上载目录中是否以$_POST['key']数据开头的文件。 You can say yes or no, depending on if that file exists. 您可以说是或否,具体取决于该文件是否存在。 And you can also attach something to the email, but that's beyond the scope here. 您还可以将某些内容附加到电子邮件中,但这超出了此处的范围。 Search on stack overflow for php mail mime attachment or something of that nature. 在堆栈溢出中搜索php邮件mime附件或类似性质的东西。

Also, you could store that key in a database or session, upon completion of the ajax upload script, and check for that instead of tacking it onto the file name. 同样,您可以在完成ajax上传脚本之后将该密钥存储在数据库或会话中,然后进行检查而不是将其添加到文件名中。 There are lots of ways to accomplish this. 有很多方法可以完成此任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM