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 = "uniqueaddress#m.facebook.com";
$from = "email#mysite.com";
$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
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
Related
I can't seem to get my email activation message to be sent in my new host called infinity-free.
I tried to use phpmailer as well as the mail function but can't see my html content.
$to = $email;
//sender
$from = 'pianocourse101#hotmail.com';
$fromName = 'PianoCourse101';
//email subject
$subject = 'Activate your Primer Level Membership Plan!';
//attachment file path
$file = "codexworld.pdf";
//email body content
$htmlContent = "<h1>Activate your Primer Level Membership Plan!</h1>
<p>Dear $first $last, <br />Thank you for registering your Primer Level Membership Plan with PianoCourse101! You are receiving this e-mail because you or someone else claiming to be you has selected a Primer Level Membership Plan \n\nIf you believe that this is a mistake, please send us a ticket with the subject \"How to cancel my Primer Level Membership Plan?\" and allow at least 48 hours before receiving a reply.\n\nHowever, if this is correct, then you must activate your Primer Level Membership Plan by clicking on the link below: \n\n Click here to activate your Primer Level Membership Plan.\n\nAlternatively, you can use the following token to manually activate your Level 3 Yearly Membership Plan by clicking on the 'Activate Membership\s Section:' \n\nToken:.$token4;
</p>";
//header for sender info
$headers = "From: $fromName"." <".$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 = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
//preparing attachment
if(!empty($file) > 0){
if(is_file($file)){
$message .= "--{$mime_boundary}\n";
$fp = #fopen($file,"rb");
$data = #fread($fp,filesize($file));
#fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" .
"Content-Description: ".basename($file)."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $from;
//send email
$mail = mail($to, $subject, $message, $headers, $returnpath);
//email sending status
echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1
>";
I have also used phpmailer with similar contents but can't seem to get it send through....
I've seen the other questions/answers in StackOverflow but I cannot for the life of me get this to work correctly, and I'm really curious to see what I'm doing wrong.
An insurance company has PDFs that they'd like their customers to fill online and submit via their site. The PDF form will be sent via email as a PDF attachment all filled out.
I have a PHP script that sends the PDF, but it's not saving form data (names, addresses, etc.). It's only sending the blank PDF. Here's the code:
<?php
$fileatt = "file-name.pdf";
$fileatt_type = "application/pdf";
$fileatt_name = "file-name.pdf";
$email_from = "From"; // Who the email is from
$email_subject = "Form"; // The Subject of the email
$email_message = "Text.";
$email_to = "someemail#gmail.com"; // Who the email is to
$headers = "De: ".$email_from;
//no need to change anything else under this point
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$ok = #mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo 'Sent...';
//unlink($fileatt); //NOW WE DELETE THE FILE FROM THE FOLDER pdfs
}
else {
echo 'Error...';
}
?>
I appreciate any input/feedback. I've thought about using PHPMailer but I think this is like 99% done and I'm curious to see what it's missing?
(The PDF file was created with Word then using Adobe Acrobat Pro all the input fields and the submit button was created, the submit button points to the PHP script that sends the PDF)
I have this script that it was posted a while back and it works, but ...
In Safari works find (goes through the browser) not problem.
FireFox & Opera forces you to open Acrobat reader. When you submit from Acrobat Reader (stand along) the php script submits sends the email with attachment but Acrobat Reader hangs "receiving data..." then times out. Email with attachment work fine.
Chrome opens within browser submits the pdf but stays on the pdf page does not redirect. The attachment send from Chrome comes in the email but it is empty, the pdf file does not open.
My question is: What is Acrobat Reader waiting to receive? and What is going on with Chrome?
Here is the code
$fileatt = date("d-m-Y-His") . ".pdf"; // Creates unique PDF name from the date
copy('php://input',"pdfs/".$fileatt); // Copies the pdf form data to a folder named pdfs
$fileatt = "pdfs/".$fileatt; // Path to the file gives the pdfs folder plus the unique file name we just assigned
$fileatt_type = "application/pdf"; // File Type
$fileatt_name = "Application Form_".$fileatt.".pdf"; // Filename that will be used for the file as the attachment when it is sent
$email_from = "mywebsite"; // Who the email is from
$email_subject = "Completed online Applications"; // The Subject of the email
$email_message = "Please find a recent online application attached.
";
$email_message .= "Any problems please email me...
"; // Message that the email has in it
$email_to = "youremail#yourserver.com"; // Who the email is to
$headers = "From: ".$email_from;
//no need to change anything else under this point
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$ok = #mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
unlink($fileatt); //NOW WE DELETE THE FILE FROM THE FOLDER pdfs
Header("Location: nextpage.php"); //where do we go once the form has been submitted.
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
Acrobat Reader is waiting for data... any data. Echo something which acknowledges receipt of the form. Chrome is sending an FDF, not a PDF. I don't think the attachment would actually be empty, but it's got to be able to open the PDF referred to in the FDF.
i want to send mail and mail is going to send but problem is that mail is empty in mail box. What is the problem in my code?
$afile = $_FILES['myFile'];
//Getting info about above taken file
$fileatttype = $afile['type'];
$fileattname = $afile['name'];
$filesize=$afile['size'];
if($fileatttype=="application/octet-stream" or $fileatttype=="text/plain" or $fileatttype=="application/msword" or $fileatttype=="application/pdf")
{
$otherData="**********************Personal Details*********************\n
Position Applied For :$Position\n
First Name :$First\n
Last Name:$LastName\n
Date Of Birth :$DD-$MM-$yy\n
Correspondence Address :$Caddress1 $Caddress2 $Caddress2\n
Permanent Address :$Paddress1 $Paddress2 $Paddress2\n
Contact No(HOME):$Home\n
Mobile :$Mobile\n
E-Mail :$EMail\n
**********************Education*********************\n
Quallification :$Quallification\n
OtherCourse:$OtherCourse\n
**********************Previous Working Details*********************\n
Company Name-$WCompany1\n
Title-$WTitle1\n
CTC-$WCTC1\n
Reasons of Leaving-$WReason1\n
Company Name-$WCompany2\n
Title-$WTitle2\n
CTC-$WCTC2\n
Reasons of Leaving-$WReason2\n
Company Name-$WCompany3\n
Title-$WTitle3\n
CTC-$WCTC3\n
Reasons of Leaving-$WReason3\n
Company Name-$WCompany4\n
Title-$WTitle4\n
CTC-$WCTC4\n
Reasons of Leaving-$WReason4\n
Current CTC:$CCTC\n
Expected CTC:$ECTC\n
Notice Period Required :$NoticePeriod\n
Total no of years experience :$TotalExperience Years\n
Current Location :$Clocation\n
Preferred Location:$Plocation\n
Resume:$Resume\n
**********************Family Details*********************\n
Father / Guardian Name :$Fname\n
Father / Spouse: Occupation:$Focc\n
Kids:$Kids\n
Age of Kids:$AOK\n
";
$to="renu_activa#yahoo.co.in";
$from=$_POST['First'];
$subject=$Position;
$headers = "From: $First";
if($filesize>0)
{
$file = fopen($afile['tmp_name'],'rb');
$data = fread($file,$afile['size']);
fclose( $file );
}
//Making a random number to use afterwards with help of current time
$semi_rand = md5( time() );
//Defining the type of email as Mime email
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//Appending to headers, telling that its multipart message with text and attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
//The text part of message in variable $otherData with other details
$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" .
$otherData . "\n\n";
//Encoding all the data read from file to "base64" the standard for email attachments
$data = chunk_split(base64_encode($data));
//Appending the file data to the email including the file name etc
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$sentmail=mail($to, $subject, $message, $headers);
if($sentmail)
{
header('location: career-with-us.php');
}
else
{
echo "Mail Not Send Successfully....";
}
}
else
{
echo "Wrong format: Please upload only PDF/DOC/DOCX/TXT file format...";
}
I am not getting why its empty neither textbox value nor file attachment is showing in mail. Its totally empty.
You define a new variable for the body of the email.
$mess = 'Please check it';
$messa = '*****...
I'm assuming you meant
$mess = 'Please check it';
$mess .= '*****...
I use PHP script to send email with multiple attachments, it works great for gmail, but in Microsoft Outlook i also see blank file ATT00010.txt (random numbers.) as attachment. And when i send email from outlook with multiple attachments as well it does not show no file like this.
I echo'ed output from email script and there is no such file in code. Can someone tell me how to remove this file from outlook?
Email script is below.
// array with filenames to be sent as attachment
$files = array("file_1.ext","file_2.ext","file_3.ext",......);
// email fields: to, from, subject, and so on
$to = "mail#mail.com";
$from = "mail#mail.com";
$subject ="My subject";
$message = "My message";
$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 "<p>mail sent to $to!</p>";
} else {
echo "<p>mail could not be sent!</p>";
}
If you want something that's a little less of a pain to use and send attachments with, try Swift Mailer. (swiftmailer.org) I've been using it in my projects and it works great.
Here's an example:
$message = Swift_Message::newInstance()
->setSubject('Webinar Registration')
->setFrom(array('replyto#example.org' => 'From Name'))
->setTo(array('destination#example.org'))
->setBody($MESSAGE_TEXT)
;
$message->attach(Swift_Attachment::fromPath('SOME_FILE_PATH'));
$transport = Swift_SmtpTransport::newInstance('127.0.0.1', 25);
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
Just my two cents.
Otherwise, I was going to mention what someone else already beat me to -- check the boundaries.
The last boundary line in a multipart/* message must have -- appended at the end, in addition to what all of the other boundary lines have. A consumer can use that to recognize the end of a message.
Apparently Outlook treats the absence of the correct ending as an indication that the message has been truncated, and then does the best it can to display whatever it did receive.
Its my second account, i actually found solution and don't need no library or class at all although i might turn this into class and add some stuff, its always better to have full understanding of process not just from, to, files etc fields.
Solution is simple here just replace last part with
if ($x == count($files)-1)
$message .= "--{$mime_boundary}--\r\n";
else
$message .= "--{$mime_boundary}\n";
\r is not necessary
if you just put -- it will use it many times inside loop IF checks if this is last loop.