Reputation: 1329
We run the facebook fan page www.facebook.com/GowerLive which features images and updates from our 3 web cameras on the Gower Peninsula; I want to use the feature on Facebook which allows you to email photos directly to your fan page using a unique email address on a CRON job at 8pm each day.
I have tested the email address... That works fine and I can submit images however my PHP Script doesn't display the photos. It will post the subject to facebook but that's it.
Firstly, is this the best way to get the images up to my fan page?
Secondly, am I using the right format of email for this to work as in Multipart Mime Type?
This is my script which I currently have running on a 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!";
}
thanks
Lee
Upvotes: 4
Views: 404
Reputation: 1908
Lee,
You might want to look at the Facebook Graph API. I'm not sure if it will work on Fan pages, but see no reason for it not to. Ignore the blog post title and scroll down to the second piece of the article as to how to create an album and upload photos to it.
https://developers.facebook.com/blog/post/498/
The Facebook Graph API page to do with photos is located at the following URL:
http://developers.facebook.com/docs/reference/api/photo/
Or alternatively create an ifttt script on http://ifttt.com as it might be easier.
Jon
Upvotes: 1