我有一个用于从图像上传器创建HTML页面的脚本,唯一的问题是它在每次上传时都会覆盖它本身,我想改变它以便我收到一封电子邮件。
想法?
<?php
$destination_dir = "uploaded/";
$targetPath = dirname($_SERVER['SCRIPT_URI']) . "/";
$html_start = "
<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<title>Upload results</title>
</head>
<body>
";
$html_end = "
</body>
</html>
";
// Check if there are AdditionalStringVariable
$result = "AdditionalStringVariable: " . $_POST["AdditionalStringVariable"];
$result .= "<br>";
// Process value of QIU_thumbnails_Imagedata field, this is JPEG-files array of generated thumbnails
if($_FILES[QIU_thumbnails_Imagedata])
{
foreach ($_FILES[QIU_thumbnails_Imagedata][name] as $key => $value)
{
$uploadfile = $destination_dir . basename($_FILES[QIU_thumbnails_Imagedata][name][$key]);
if (move_uploaded_file($_FILES['QIU_thumbnails_Imagedata']['tmp_name'][$key], $uploadfile))
{
$big_image_name = $_FILES[Imagedata][name][$key];
$result .= "<a href='" .$big_image_name. "'>" . "<img border = '0' src='".$value . "'/></a><br><br>";
}
}
}
//
$result .= "<br>";
// Process value of Imagedata field, this is JPEG-files array
foreach ($_FILES[Imagedata][name] as $key => $value)
{
$uploadfile = $destination_dir . basename($_FILES[Imagedata][name][$key]);
if (move_uploaded_file($_FILES['Imagedata']['tmp_name'][$key], $uploadfile))
{
$result .= "File uploaded: <a href='". $value . "'>" . $value . "</a><br>";
}
}
//
$result .= "<br>";
//
// Process GlobalControlData field, this is the array of serialized data for Global controls
// the value for each control is: id|value
if($_POST[GlobalControlData])
{
foreach ($_POST[GlobalControlData] as $key => $value)
{
$globalControlExploded = explode("|", $value);
$result .= "\n" . "GlobalControlData:\n\t" . $globalControlExploded[0] ."\t:\t" . $globalControlExploded[1] . "<br>";
}
}
//
// Process LocalControlData field, this is the array of serialized data for Local controls
// value for each image is: image||id1|value1^id2|value2^id3|value3, where image - is picture name, id - is unique control ID , and a value - control value
if($_POST[LocalControlData])
{
foreach ($_POST[LocalControlData] as $key => $value)
{
$exploded = explode("||", $value);
$parentFile = $exploded[0];
$result .= "<br>" . $exploded[0] . "<br>";
$explodedToControls = explode("^", $exploded[1]);
foreach ($explodedToControls as $cnt => $val)
{
$eachControl = explode("|", $val);
$result .= "\tcontrol:\t" . $eachControl[0] . ", value:\t" . $eachControl[1] . "<br>";
}
//
}
}
//
$result = $html_start . $result . $html_end;
//
if(@$fp = fopen($destination_dir.'index.html', 'w')) {
fwrite($fp, $result);
fclose($fp);
}
132 echo $targetPath . $destination_dir;
133
134 ?>
我刚添加了这个:
135
136 $to = 'michael.robinson@mac.com';
137 $subject = 'Baublet Order Received';
138 $headers = 'From: orders@baublet.com '. "\r\n" .
139 'MIME-Version: 1.0' . "\r\n" .
140 'Content-type: text/html; charset=utf-8' . "\r\n";
141 mail($to, $subject, $result, $headers");
142
143 ?>
答案 0 :(得分:1)
据我所知,您不想将HTML保存到服务器,而是希望将其作为电子邮件发送到某个地方。这就是你要求的吗?如果没有,请编辑/评论您的问题,以澄清您的需求。
块
if(@$fp = fopen($destination_dir.'index.html', 'w')) {
fwrite($fp, $result);
fclose($fp);
}
负责在服务器的文件系统中写入文件,可能会替换某些内容。如果您不想将HTML保存为服务器上的文件,则只需要删除该块(删除它或将其注释掉)。
到那时你已经在$result
变量上生成了HTML(如果你仔细看一下,这就是原始代码保存到文件中的内容);所以,如果你想通过邮件发送,你已经拥有了自己的身体。找出“from”,“to”,“CC”(如果有的话)和“BCC”(如果有的话)地址,以及邮件的主题。 “from”通常以文字或常量形式出现,但也可以是POSTed表单中的输入字段。 “到”地址取决于您发送邮件的意思。然后使用这样的东西实际邮寄它:
$to = "here goes the destination address";
$subject = "here you put the subject line for the e-mail";
$headers = "From: " . $whatever_your_sender_address_is . "\r\n" .
"MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n";
mail($to, $subject, $result, $headers);
有关mail()函数的更多详细信息,请查看http://ie2.php.net/manual/en/function.mail.php上的mail()文档。 请注意,在这种情况下,您需要定义至少3个标题:必须始终指定“From”(某些服务器端邮件应用程序可能具有默认的“from”地址,但始终建议您坚定不移)。 “MIME-Version”和“Content-type”标头用于确保邮件以HTML格式发送,而不是以文本形式发送。根据您的需要,您可能需要添加“回复”,“CC”,“BCC”和其他标题:在这种情况下,只需将它们附加到$ header变量,用“\ r \ n”分隔,在调用mail()之前。
希望这有帮助。