我有一个html表单和一个php文件。 php文件有一个用于解析附件的函数,然后php应该将整个表单发送到带有解析文件的电子邮件地址。我不知道如何附加文件并确保将所有信息发送到电子邮件。我是初学者,所以任何帮助将不胜感激。 这是html代码:
<form METHOD = "POST" action="Parsing.php" name="form" enctype = "multipart/form-data">
<fieldset>
<legend> Enter Information </legend>
<p>
Plant:
<label for 'Plant_ID'> </label> <br>
<input type="text" name="Plant_ID" /> <br>
</p>
<p>
Date:
<label for 'Datedetails'> </label> <br>
<input type="date" name="Datedetails" placeholder="YYYY-MM-DD" required pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" /><br>
</p>
<p>
Analysis:
<label for 'Analysis'> </label> <br>
<input type= "text" name= "Analysis" /> <br>
</p>
<p>
Attachment:
<label for 'file'> </label> <br>
<input type="file" name="file" accept = "video/*, image/*, media_type, file_extension" /> <br>
</p>
<input type="submit" value="submit" name = "submit" id="submit"/> <br>
</fieldset>
</form>
这是我目前的php文件:
<?php
$Plant_ID = $_POST['Plant_ID'];
$Process_Order = $_POST['Process_Order'];
$Material = $_POST['Material'];
$Datedetails = $_POST['Datedetails'];
$Batch_Number = $_POST['Batch_Number'];
$Processing_Stage = $_POST['Processing_Stage'];
$Analysis = $_POST['Analysis'];
$file = $_POST['file'];
function generatePlotForSPA($file, $targetFile) { //replace $source with $file
//code to parse spa files and plot
$sourceFile = fopen($file, "rb");
fseek($sourceFile, 386);
$targetOffset = current(unpack("v", fread($sourceFile, 2)));
if($targetOffset > filesize($file)) {
return false;
}
fseek($sourceFile, 390);
$dataLength = current(unpack("v", fread($sourceFile, 2)));
if($dataLength + $targetOffset > filesize($file)) {
return false;
}
fseek($sourceFile, $targetOffset);
$rawData = fread($sourceFile, $dataLength);
$rawDataOutputPath = $file . "_raw_data";
$outputFile = fopen($rawDataOutputPath, "w");
fwrite($outputFile, $rawData);
fclose($outputFile);
$gnuScript = "set terminal png size {width},{height};
set output '{output}';
unset key;
unset border;
plot '<cat' binary filetype=bin format='%float32' endian=little array=1:0 with lines lt rgb 'black';";
$targetScript = str_replace("{output}", $targetFile, $gnuScript);
$targetScript = str_replace("{width}", 500, $targetScript);
$targetScript = str_replace("{height}", 400, $targetScript);
$gnuPath = "gnuplot";
$outputScript = "cat \"" . $rawDataOutputPath . "\" | " . $gnuPath . " -e \"" . $targetScript . "\"";
exec($outputScript);
if(!file_exists($targetFile)) {
return false;
}
return true;
}
if(!isset($_POST['submit'])){
//This page should not be accessed directly, this is the backhand service
echo "error, you need to submit the form";
}
//validate
if(empty($Plant_ID)|| empty($Process_Order) || empty($Material) || empty($Datedetails) || empty($Batch_Number) || empty($Processing_Stage) || empty($Analysis) || empty($file)){
echo "All the fields are mandatory, Please provide all the information"
exit;
}
$email_subject = "IR data";
$to = "abc@xyz.com";
$mail($to, $subject, "Plant ID:" .$Plant_ID, " Material:" .$Material, "Date:" .$Datedetails , "Process Order:" .$Process_Order , "Batch Number:" .$Batch_Number, "Processing Stage:" .$Processing_Stage, "Analysis:" .$Analysis , "File:" .$targetFile);
echo "The information has been stored" ;
?>
我在网上读到Swift Mailer可能会对我有所帮助,但我不确定如何使用它。非常感谢提前!