メールでfacebookに投稿する
以下のページのjphpmailer.phpをインクルードして利用。
PHPで日本語メールを送る – 応用編 (添付ファイル、HTMLメール) - EC studio 技術ブログ
mimetypeをちゃんと指定しないとfacebookは認識してくれない。ディバグ用に同報送信しているthunderbirdではデコードされたんだが。
<?php function send_facebook($body,$attachfiles=""){ global $facdebook_post_address; $mail = new JPHPMailer(); $mail->AddAddress($facdebook_post_address); $mail->AddAddress("nanchara@nanchara.com");//debug用にPCにも同報 $mail->Subject = $body; $mail->Body = $body; //facebook的には不要だが、空だとphpmailerがエラーになる。 //添付ファイル追加 attach($mail,$attachfiles); if (!$mail->send()){ echo("メールが送信できませんでした。エラー:".$mail->getErrorMessage()); } } function attach($mail,$attachfiles){ if(is_array($attachfiles) && count($attachfiles) > 0){ foreach($attachfiles as $attachfile){ $pathinfo = pathinfo($attachfile); $ext = strtolower($pathinfo['extension']); $name = $pathinfo['basename']; switch($ext){ case "jpg": $mimetype='image/jpeg';continue; case "3gp": $mimetype='video/3gpp';continue; default: continue 2; } $mail->addAttachment($attachfile,$pathinfo['basename'],'base64',$mimetype); } } } ?>