2010-03-20 44 views
2

我得到了這個腳本,用於從圖片上傳器創建HTML頁面,唯一的問題是它在每次上傳時都覆蓋自身,我想改變它以便獲得改爲發送電子郵件。將生成php腳本的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 = '[email protected]'; 
137 $subject = 'Baublet Order Received'; 
138 $headers = 'From: [email protected] '. "\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」(如果有)地址,以及郵件的主題。 「來自」一個經常以字面或常量形式出現,但也可能來自POST表單的輸入字段。 「到」地址取決於您發送郵件的意思。然後使用類似這樣的實際郵寄它:

$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); 

看看郵件()的上http://ie2.php.net/manual/en/function.mail.php有關mail()函數的詳細信息的文檔。 請注意,在這種情況下,您至少需要定義3個標頭:必須始終指定「發件人」(某些服務器端郵件應用程序可能具有默認的「來自」地址,但建議您堅實地踏實) 。 「MIME版本」和「Content-type」標題確保郵件以HTML格式發送,而不是以文本形式發送。根據您的需要,您可能需要添加「回覆」,「CC」,「BCC」和其他標題:在這種情況下,只需將它們追加到$ he​​aders變量中,並用「\ r \ n」分隔,在調用郵件之前()。

希望這會有所幫助。

+0

這就是你的時間...你理解我的問題,結果正在工作。郵件需要一點時間才能到達......但它確實發生了。 –

+0

我剛剛更改了電子郵件地址,突然之間?>沒有長時間的紅色,它不工作......任何想法如何正確地關閉它? Michael 我編輯了問題以顯示插件上的位置。 –

+0

你剛剛添加了代碼塊作爲更新後的帖子建議?首先,這留下了「保存到文件」的部分(只要它是你想要的就可以),但更關鍵的是:在第134行上,你已經有了一個結束符「?>」:如果你希望在那之後的代碼是作爲PHP處理,你必須刪除它或添加一個新的「<?php」開啓者。在這種情況下,你所需要的就是完全刪除第134行,並且事情應該起作用。 另外,您可能需要檢查不匹配的引號,方括號等:這些問題可能相當麻煩,而且經常不被注意。 –