Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将生成html的php脚本转换为自动电子邮件脚本_Php_Scripting_Email - Fatal编程技术网

将生成html的php脚本转换为自动电子邮件脚本

将生成html的php脚本转换为自动电子邮件脚本,php,scripting,email,Php,Scripting,Email,我用这个脚本从一个图像上传器创建一个HTML页面,唯一的问题是每次上传时它都会覆盖它自己,我想更改它,这样我就可以收到一封电子邮件 想法 <?php $destination_dir = "uploaded/"; $targetPath = dirname($_SERVER['SCRIPT_URI']) . "/"; $html_start = " <!doctype html public \"-//w3c//dtd html 4.0 transitional//en\"&g

我用这个脚本从一个图像上传器创建一个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   ?>  

我知道,您不想将HTML保存到服务器,而是想将其作为电子邮件发送到某个地方。这就是你想要的吗?如果没有,请编辑/评论您的问题,以澄清您的需要

街区

if(@$fp = fopen($destination_dir.'index.html', 'w')) {
      fwrite($fp, $result);
      fclose($fp);
}
负责在服务器的文件系统中写入文件,可能会替换某些内容。如果不想将HTML保存为服务器上的文件,只需删除该块(删除或注释掉)

此时,您已经在
$result
变量上生成了HTML(如果仔细查看,原始代码将保存到文件中);所以如果你想通过邮件发送,你已经有了你的身体。找出“发件人”、“收件人”、“抄送”(如果有)和“密件抄送”(如果有)地址,以及邮件的主题。“from”一词通常作为文本或常量,但也可能是来自发布表单的输入字段。“收件人”地址取决于您要将邮件发送到哪里。然后用这样的方式实际邮寄:

$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()函数的更多详细信息,请参阅上的mail()文档。 请注意,在这种情况下,您需要定义至少3个标题:“发件人”必须始终指定(某些服务器端邮件应用可能具有默认的“发件人”地址,但建议始终脚踏实地)。“MIME版本”和“内容类型”标题用于确保邮件以HTML而不是文本的形式发送。根据需要,您可能需要添加“Reply to”、“CC”、“BCC”和其他标题:在这种情况下,只需将它们附加到$headers变量中,在调用mail()之前用“\r\n”分隔


希望这能有所帮助。

您想通过电子邮件发送什么?文件已写入的消息?图像本身?那是你的时间…你理解我的问题,结果是有效的。这封邮件花了一点时间才收到…但它确实收到了。我刚更改了电子邮件地址,突然?>不再是红色,它不工作了…有没有办法正确地结束这封邮件?Michael我编辑了这个问题以显示附加组件上的位置。您是否按照更新帖子的建议添加了代码块?首先,这将“保存到文件”部分保留在那里(只要它是您想要的,就可以了),但更关键的是:在第134行,您已经有了一个结束“?>”:如果您希望之后的代码作为PHP处理,您必须删除它或添加一个新代码“我发出的两封电子邮件都是一个奇怪的字符串,当我将其留空时,它会被填充,并且$header的格式不正确,我正在处理这个问题,但它现在正在上传和发送电子邮件。是 啊谢谢大家。
$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);