我们运行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