検索
ホームページphp教程php手册エッセンス領域の MIME クラスを借用して、電子メールを送信するための基本的な小さなものを書きました (2)

マイム|エッセンス

sendmail.php4


//添付ファイルを送信するためのクラスをロードします
require('html_mime_mail.inc');

if($update!=""){ //添付ファイルがある場合

//アップロード添付ファイルif(!file_exists( "c:/ftptmp /".$ myfile_name)){
($ fp = fopen(" c:/ftptmp /".$ myfile_name、 'r')、filesize($ myfile));
myfile_name); ️ echo "同じ名前のファイル!";
exit();
}


//クラスの新しいインスタンスを作成し、添付ファイルを追加します
$mail = new html_mime_mail();
$mail->add_attachment($attachment, $myfile_name, 'application/octet-stream');

/*--- ------------------この段落では次のことを示しますHTMLレターの送り方------------------------------------------
$filename = 'background.gif';
$backgrnd = fread($fp = fopen($filename, 'r'), filesize($filename)) ;
fclose($fp);

$text = 'これはテストです。';
$html = '

成功! ;

';

$mail->add_html_image($backgrnd, 'background.gif' , 'image/gif');
$mail->add_html( $html, $text);
------------------------ -------------- ---------------------------------- --------*/

//読むテキストを入力し、レターをカプセル化して送信します
$mail->body=$bodytext;
$mail->build_message();

$backvalue= $ Mail-& GT Send ('', $ ReceivemailBox, ' ', $ Sendmailbox, $ Subject, ''); & gt; レターを送信してください。戻るには [OK] を押してください。 ');window.location='default.htm'";
}
else{ //添付ファイルがない場合
$backvalue=mail($receivemailbox,$subject,$bodytext,"From:" . $sendmailbox . "nX-Mailbox: PHP/" . ');window.location='default.htm'& を押して戻ります。それ;/script>";
}
else{
echo "
?>

html_mime_mail.inc このクラスはお借りして使用させていただきました。
class html_mime_mail{

var $headers;
var $body;
var $multipart;
var $mime;
var $html;
var $html_text;
var $html_images = array();
var $ cids = array();
var $do_html;
var $parts = array();

/** **************************************
** コンストラクター関数。ヘッダーを設定します
** (指定されている場合)。
***************************************/
function html_mime_mail($headers = ''){
$this->headers = $headers;
}

/***************************************
** メールにHTML部分を追加します
* * 画像名も
** content-id に置き換えられます。
************************************ ***/
function add_html($html, $text){
$this-> do_html = 1;
$this->html = $html;
$this->html_text = $text;
if(is_array($this->html_images) A​​ND count($this->html_images) > 0){
for($i=0; $ihtml_images); $i++){
$this->html = ereg_replace($this->html_images[$i][' name'], 'cid:'.$this->html_images[$i]['cid'], $this->html);
}
}
}

/****************************************
** メールの HTML 部分を構築します。
*** ***********************************/
関数 build_html($orig_boundary){
$sec_boundary = '=_'.md5(uniqid(time()));
$thr_boundary = '=_'.md5(uniqid(time()));

if(! is_array($this->html_images)){
$this->multipart.= '--'.$orig_boundary."rn";
$this->multipart.= 'Content-Type: multipart/alternative; border="'.$sec_boundary.""rnrnrn";

$this->multipart.= '--'.$sec_boundary."rn";
$this->multipart.= 'Content-Type: text /plain'."rn";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."rnrn";
$this->multipart.= $this->html_text."rnrn" ;

$this->multipart.= '--'.$sec_boundary."rn";
$this->multipart.= 'Content-Type: text/html'."rn";
$this- >multipart.= 'コンテンツ転送エンコーディング: 7 ビット'."rnrn";
$this->multipart.= $this->html."rnrn";
$this->multipart.= '- -'.$sec_boundary."--rnrn";
}else{
$this->multipart.= '--'.$orig_boundary."rn";
$this->multipart.= 'Content-Type : マルチパート/関連。 border="'.$sec_boundary.""rnrnrn";

$this->multipart.= '--'.$sec_boundary."rn";
$this->multipart.= 'Content-Type: multipart /代替; border="'.$thr_boundary.""rnrnrn";

$this->multipart.= '--'.$thr_boundary."rn";
$this->multipart.= 'Content-Type: text /plain'."rn";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."rnrn";
$this->multipart.= $this->html_text."rnrn" ;

$this->multipart.= '--'.$thr_boundary."rn";
$this->multipart.= 'Content-Type: text/html'."rn";
$this- >multipart.= 'コンテンツ転送エンコーディング: 7 ビット'."rnrn";
$this->multipart.= $this->html."rnrn";
$this->multipart.= '- -'.$thr_boundary."--rnrn";

for($i=0; $ihtml_images); $i++){
$this->multipart.= '-- '.$sec_boundary."rn";
$this->build_html_image($i);
}

$this->multipart.= "--".$sec_boundary."--rnrn";
}
}
/****************************************
** 埋め込みリストに画像を追加します
* * 画像。
**************************************/
function add_html_image($file, $name = '', $c_type='application/octet-stream'){
$this->html_images[] = array( 'body' => $file,
'name' => $name,
'c_type' => md5(uniqid(time())) );
}

/ ****************************************
** 添付ファイルのリストにファイルを追加します。
**************************************/
function add_attachment($file, $name = '', $c_type='application/octet-stream'){
$this->parts[] = array( 'body' => $file,
'名前' => $name,
'c_type' => $c_type );
}

/****************************************
**
** の埋め込み画像部分を構築しますhtmlメール
**************************************/
function build_html_image($i){
$this->multipart.= 'Content-Type: '.$this->html_images[$i] ['c_type'];

if($this->html_images[$i]['name'] != '') $this->multipart .= '; name="'.$this->html_images[$i]['name'].""rn";
else $this->multipart .= "rn";

$this->multipart.= 'Content-ID: html_images[$i]['cid'].">rn";
$this->multipart.= 'Content-Transfer-Encoding:base64'。 "rnrn";
$this->multipart.= chunk_split(base64_encode($this->html_images[$i]['body']))."rn";
}

/****** *********************************
** マルチパートの単一パートを構築します
** message.
***************************************/
function build_part($ i){
$message_part = '';
$message_part.= 'Content-Type: '.$this->parts[$i]['c_type'];
if($this->parts[$i ]['名前'] != '')
$message_part .= '; name="'.$this->parts[$i]['name'].""rn";
else
$message_part .= "rn";

// コンテンツのエンコーディングを決定します。
if($this ->parts[$i]['c_type'] == 'text/plain'){
$message_part.= 'Content-Transfer-Encoding: 7bit'."rnrn";
$message_part.= $this-> ;parts[$i]['body']."rn";
}else{
$message_part.= 'Content-Transfer-Encoding:base64'."rn";
$message_part.= 'Content-Disposition:attachment ; filename="'.$this->parts[$i]['name'].""rnrn";
$message_part.= chunk_split(base64_encode($this->parts[$i]['body'] ))."rn";
}

return $message_part;
}

/****************************************
**
** リストからマルチパートメッセージを構築します($this->parts).
**************************************/
function build_message(){
$boundary = '=_'.md5(uniqid(time()) );

$this->headers.= "MIME-Version: 1.0rn";
$this->headers.= "Content-Type: multipart/mixed; border="".$boundary.""rn ";
$this->multipart = '';
$this->multipart.= "これは MIME エンコードされたメッセージです。rn作成者: html_mime_mail.class.rnhttp://www.heyes-computing.net/scripts を参照/ コピー用。rnrn";

if(isset($this->do_html) AND $this->do_html == 1) $this->build_html($boundary);
if(isset($this ->body) AND $this->body != '') $this->parts[] = array('body' => $this->body, 'name' => '', 'c_type' => 'text/plain');

for($i=(count($this->parts)-1); $i>=0; $i--){
$this- >multipart.= '--'.$boundary."rn".$this->build_part($i);
}

$this->mime = $this->multipart."--" .$boundary."--rn";
}

/***************************************
** メールを送信します
***** *********************************/
function send($to_name, $to_addr, $from_name, $from_addr, $subject = '', $headers = '') {

if($to_name != '') $to = '"'.$to_name.'" ';
else $to = $to_addr;
if($from_name ! = '') $from = '"'.$from_name.'" ';
else $from = $from_addr;
$this->headers.= 'From: '。 $from."rn";
//$this->headers.= $headers;
mail($to, $subject, $this->mime, $this->headers);
}

/ ****************************************
** ダイレクトでお届けする場合はこちらの方法をご利用ください
** SMTP接続。 Manuel Lemos の
** smtp メール配信クラスに依存しています:
** http://phpclasses.upperdesign.com
**
** void smtp_send( string *Name* of smtp object,
** string From address 、
** 配列 To アドレス、
** 配列 ヘッダー、
** 文字列 本文)
**************************** ***********/
function smtp_send($smtp_obj, $from_addr, $to_addr){
global $$smtp_obj;
$smtp_obj = $$smtp_obj;

if(substr($this->headers, -2 ) == "rn") $this->headers = substr($this->headers,0,-2);
$this->headers =explode("rn", $this->headers) ;

$smtp_obj->sendmessage($from_addr, $to_addr, $this->headers, $this->mime);
}

} // クラス終了
?>



声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

mPDF

mPDF

mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境