POP3サーバから本文の受信

  control.php



「POP3サーバからヘッダ情報の受信」から呼び出す事を想定しています
control.php?uid=メッセージのUID で表示されます


  
<?
# **********************************************************
# 外部ファイル
# **********************************************************
require_once( "common.php" );
require_once( "model.php" );

# **********************************************************
# 定数定義
# **********************************************************
define( 'PASS_MESSAGE', 1 );

define( 'VIEW_MESSAGE', 'viewmessage.php' );
define( 'VIEW_CUR', 'view.php' );

# **********************************************************
# グローバル変数
# **********************************************************
$ErrMessage	= '';
$OutData	= '';
$Mail		= FALSE;

# **********************************************************
# 初期処理
# **********************************************************
if ( !extension_loaded( "imap" ) ) {
	dl("php_imap.dll");
}
if ( !extension_loaded( "mbstring" ) ) {
	dl("php_mbstring.dll");
}

$Mail = imap_open("{サーバアドレス:110/pop3}INBOX", "ユーザー", "パスワード");
if ( !$Mail ) {
	$ErrMessage = "メールボックスをオープンできません";
	$_POST['GNO'] = PASS_MESSAGE;
}

# **********************************************************
# 処理コントロール
# **********************************************************
if ( $ErrMessage == "" ) {
	CheckDataHead( );
	if ( $ErrMessage != "" ) {
		$_POST['GNO'] = PASS_MESSAGE;
	}
	else {
		GetData( );
		if ( $ErrMessage != "" ) {
			$_POST['GNO'] = PASS_MESSAGE;
		}
	}
}

# **********************************************************
# ビュー
# **********************************************************
switch( $_POST['GNO'] ) {
	case PASS_MESSAGE:
		require_once( VIEW_MESSAGE );
		break;

	default:
		EditDataHead( );
		require_once( VIEW_CUR );
		break;
}

if ( !$Mail ) {
	imap_close( $Mail );
}

# **********************************************************
# デバッグ
# **********************************************************
#DispData();
?>
  



  model.php



  
<?
# **********************************************************
# データの読出し
# **********************************************************
function GetData(  ) {

	global $ErrMessage;
	global $MessageCount;
	global $Mail;
	global $OutData;

	# メッセージのヘッダ情報の概要
	$MailStruct = imap_fetchstructure( $Mail, $_POST['uid'], FT_UID );

	$OutData .= "<TR>\n";
	$OutData .= "<TD class=MyCell>タイプ</TD>";
	$OutData .= "<TD class=MyCell>";
	$OutData .= $MailStruct->type;
	$OutData .= "</TD>\n";
	$OutData .= "</TR>\n";

	$OutData .= "<TR>\n";
	$OutData .= "<TD class=MyCell>エンコーディング</TD>";
	$OutData .= "<TD class=MyCell>";
	$OutData .= $MailStruct->encoding;
	$OutData .= "</TD>\n";
	$OutData .= "</TR>\n";

	$OutData .= "<TR>\n";
	$OutData .= "<TD class=MyCell>サブタイプの有無</TD>";
	$OutData .= "<TD class=MyCell>";
	$OutData .= $MailStruct->ifsubtype;
	$OutData .= "</TD>\n";
	$OutData .= "</TR>\n";
	if ( $MailStruct->ifsubtype ) {
		$OutData .= "<TR>\n";
		$OutData .= "<TD class=MyCell>サブタイプ</TD>";
		$OutData .= "<TD class=MyCell>";
		$OutData .= $MailStruct->subtype;
		$OutData .= "</TD>\n";
		$OutData .= "</TR>\n";
	}

	$OutData .= "<TR>\n";
	$OutData .= "<TD class=MyCell>行数</TD>";
	$OutData .= "<TD class=MyCell>";
	$OutData .= $MailStruct->lines;
	$OutData .= "</TD>\n";
	$OutData .= "</TR>\n";

	$OutData .= "<TR>\n";
	$OutData .= "<TD class=MyCell>バイト数</TD>";
	$OutData .= "<TD class=MyCell>";
	$OutData .= $MailStruct->bytes;
	$OutData .= "</TD>\n";
	$OutData .= "</TR>\n";

	$OutData .= "<TR>\n";
	$OutData .= "<TD class=MyCell>パートの数</TD>";
	$OutData .= "<TD class=MyCell>";
	$OutData .= count($MailStruct->parts);
	$OutData .= "</TD>\n";
	$OutData .= "</TR>\n";

	if ( $MailStruct->type == 0 &&
		$MailStruct->ifsubtype &&
		$MailStruct->subtype == 'PLAIN' &&
		count($MailStruct->parts) == 0 ) {
		$Body =
			imap_body( $Mail, $_POST['uid'], FT_UID | FT_PEEK );
		$Body = mb_convert_encoding(
			$Body,
			"SJIS",
			"JIS"
		);
		$Body = str_Replace( "\r\n", "<br>", $Body );

		$OutData .= "<TR>\n";
		$OutData .= "<TD class=MyCell>本文</TD>";
		$OutData .= "<TD class=MyCell>";
		$OutData .= $Body;
		$OutData .= "</TD>\n";
		$OutData .= "</TR>\n";
	}

	if ( $MailStruct->type == 1 &&
		$MailStruct->ifsubtype &&
		$MailStruct->subtype == 'ALTERNATIVE' &&
		count($MailStruct->parts) == 2 ) {
		$Body =
			imap_fetchbody ( $Mail, $_POST['uid'], "1", FT_UID | FT_PEEK );
		$Body = mb_convert_encoding(
			$Body,
			"SJIS",
			"JIS"
		);
		$Body = str_Replace( "\r\n", "<br>", $Body );

		$OutData .= "<TR>\n";
		$OutData .= "<TD class=MyCell>本文(1)</TD>";
		$OutData .= "<TD class=MyCell>";
		$OutData .= $Body;
		$OutData .= "</TD>\n";
		$OutData .= "</TR>\n";

		$Body =
			imap_fetchbody( $Mail, $_POST['uid'], "2", FT_UID | FT_PEEK );
		$Body = quoted_printable_decode( $Body );
		$Body = htmlentities( mb_convert_encoding(
			$Body,
			"SJIS",
			"JIS"
		) );
		$Body = str_Replace( "\r\n", "<br>", $Body );

		$OutData .= "<TR>\n";
		$OutData .= "<TD class=MyCell>本文(2)</TD>";
		$OutData .= "<TD class=MyCell>";
		$OutData .= $Body;
		$OutData .= "</TD>\n";
		$OutData .= "</TR>\n";

	}
}

# **********************************************************
# 画面の編集
# **********************************************************
function EditDataHead( ) {


}

# **********************************************************
# エラーチェック
# **********************************************************
function CheckDataHead( ) {

	global $ErrMessage;
	global $Mail;
	global $MessageCount;

	$MessageCount = imap_num_msg( $Mail );
	if ( $MessageCount == 0 ) {
		$ErrMessage = "メールボックスは空です";
	}

}
?>
  



  view.php

  
<SCRIPT language=JavaScript>

// *********************************************************
// フォームのチェック
// *********************************************************
function CheckData() {

	return true;
}

</SCRIPT>


<HTML>
<HEAD>
	<META http-equiv="Content-type" content="text/html; charset=Shift_JIS">
	<TITLE>PHP 雛形</TITLE>
<STYLE>
	.MyHead {
		background-color:silver;
		font-size:12px;
	}
	.MyCell {
		background-color:white;
		font-size:12px;
	}
</STYLE>
</HEAD>
<BODY>

<FORM
	name=frmMain
	method=GET
	action=control.php
	onSubmit='return CheckData()'
>
<!-- *******************************************************
 画面定義
******************************************************** -->
<TABLE border=0 bgcolor=black cellspacing=1 cellpadding=5>
<?= $OutData ?>
</TABLE>

</FORM>

</BODY>
</HTML>

<SCRIPT for=window event=onload language="VBScript">

	window.focus()

</SCRIPT>
  



  viewmessage.php

  
<HTML>
<HEAD>
	<META http-equiv="Content-type" content="text/html; charset=Shift_JIS">
	<TITLE>メッセージ表示専用</TITLE>
<STYLE>
	.MyCell {
		background-color:silver
	}
</STYLE>
</HEAD>
<BODY>
<SPAN style='color:blue'><?= $ErrMessage ?></SPAN>
<SPAN style='color:black;font-weight:bold'><?= $Message ?></SPAN>
</BODY>
</HTML>
  













   SQLの窓    create:2005/05/07  update:2018/02/08   管理者用(要ログイン)





フリーフォントツール

SQLの窓ツール

SQLの窓フリーソフト

写真素材

一般ツールリンク

SQLの窓

フリーソフト