我們運行Facebook粉絲頁面www.facebook.com/GowerLive,其中展示了高爾半島3臺網絡攝像機的圖像和更新;我希望在Facebook上使用該功能,讓您可以在每天晚上8點的CRON工作中使用獨特的電子郵件地址將照片直接發送至粉絲頁面。通過電子郵件將照片發送到我的Facebook頁面
我測試了電子郵件地址...這工作正常,我可以提交圖像,但是我的PHP腳本不顯示照片。它會將主題發佈到Facebook,但就是這樣。
首先,這是最好的方式讓圖像到我的粉絲頁面?
其次,我是否使用正確格式的電子郵件來使用此功能,如同Multipart Mime Type一樣工作?
這是我的腳本,我現在有一個cron運行
// array with filenames to be sent as attachment
$files = array("public_html/langcam/09.jpg","public_html/langcam/13.jpg","public_html/langcam/16.jpg","public_html/caswellcam/09.jpg","public_html/caswellcam/13.jpg","public_html/caswellcam/16.jpg","public_html/llangcam/09.jpg","public_html/llangcam/13.jpg","public_html/llangcam/16.jpg");
// email fields: to, from, subject, and so on
$to = "[email protected]";
$from = "[email protected]";
$subject = "On ".date("F j, Y")." the wavebuoy at 1pm was ". $waveheightb."ft @ ".$seconds."seconds with a ".$windcompass." wind at ".$windspeedb."mph";
$message = "I normally leave this blank";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "Mail sent to $to!";
} else {
echo "Mail could not be sent!";
}
感謝
李
如果您發送電子郵件給自己而不是Facebook - 你看到圖像了嗎? – neopickaze 2012-01-15 15:42:46
是的,雖然我必須稍微更改腳本以使其與CRON一起工作,但僅限於我使用的文件路徑。要在CRON中使用它,我需要在圖像之前添加public_html /,並且不會返回任何錯誤。一些我認爲可能會導致問題的東西是進一步附加到名爲ATT00036.txt的文件的電子郵件......任何想法該文件是什麼? – 2012-01-15 15:53:36
我讓這個運行這個晚上CRON的工作,但我編輯的代碼,所以它cc'd我的個人電子郵件地址,以確保圖像肯定是連接,它通過確定我的個人電子郵件,但只發布主題行到Facebook!非常沮喪。 – 2012-01-15 23:09:37