メールを送信しサーバー側でphpに転送。
転送先PHP内、下記のコードで取得した内容をDBに保存しようとしていますが
本文($diary_body)だけが取得できません。
デバッグのために、マルチパートの画像処理はスキップしています。
PHP7.0
Mac
送信元メール Gmail
mb_language("japanese"); mb_internal_encoding("UTF-8"); $input = file_get_contents("php://stdin"); $decoder = new Mail_mimeDecode($input); $structure = $decoder->decode($params); //-------------------------------------------------- //fromを抽出 //-------------------------------------------------- $frommail=$structure->headers['from']; $frommail = addslashes($frommail); $frommail = str_replace('"','',$frommail); //署名付きの場合の処理を追加 preg_match("/<.*>/",$frommail,$str); if($str[0]!=""){ $str=substr($str[0],1,strlen($str[0])-2); $frommail = $str; } //-------------------------------------------------- //件名を抽出 //-------------------------------------------------- $subject = mb_convert_encoding(mb_decode_mimeheader($structure->headers["subject"]),mb_internal_encoding(), "auto"); //-------------------------------------------------- //本文を抽出 //-------------------------------------------------- switch(strtolower($structure->ctype_primary)){ case "text": // シングルパート(テキストのみ) $diary_body = $structure->body; break; case "multipart": // マルチパート(画像付き) foreach($structure->parts as $part){ switch(strtolower($part->ctype_primary)){ case "text": // テキスト $diary_body = $part->body; break; case "image": // 画像 /* //画像の拡張子を取得する(小文字に変換 $type = strtolower($part->ctype_secondary); //JPEGチェック(GIFやPNG形式の画像チェックなども可 if($type != "jpeg" and $type != "jpg"){ continue; } //添付内容をファイルに保存 $fp = fopen("/tmp/picture.jpg" . $type,"w" ); $length = strlen( $part->body ); fwrite( $fp, $part->body, $length ); fclose( $fp ); */ break; } } break; default: $diary_body = ""; } //この後DB格納処理 //$frommail=OK; //$subject=OK; //$diary_body=NG;
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。