Home
Main Menu
Home
Blog
Downloads
Forum
Link
Search
Category
Mobile
PHP
Google
Joomla
Cygwin
I-Apply
Linux
Plagger
Internet
Other
What's New
Recommend
RSS
E-Pagerank
添付ファイル付のメール送信クラス
Writte by Administrator   
2006/10/11 水曜日 10:18
Tag it:
Hatena
Delicious
Spurl
blogmarks

JoomlaのDBと設定諸々をGMAILにバックアップするために、
添付ファイル付のメール送信クラスを適当に作ってみた。

送れればいいやということで、別にクラスにする必要も
なかったのを適当に作ったのでかなり適当。

※注意
sendmailを使っているので、Windows上では動かない。。。

以下ソースとなる。

<?php

/**
 * メール送信クラス
 * @author labs zsrv net
 * @version 1.0.1
 */
class SendMail {

    var $form = null;
    var $to = null;
    var $subject = null;
    var $body = null;
    var $files = null;
    var $handler = null;
    var $command = null;

    /**
     * コンストラクタ
     * @param    $from        送信元アドレス
     * @param    $to            送信先アドレス
     * @param    $subject    件名
     * @param    $body        本文
     * @param    $filename    添付ファイル
     */
    function SendMail($from, $to, $subject, $body, $files = array()) {
        $this->from = $from;
        $this->to = $to;
        $this->subject = $subject;
        $this->body = $body;
        $this->files = $files;
    }

    /**
     * メール送信
     * @return        true    成功
     *                 false    失敗
     */
    function execute() {

        // メール送信
        $boundary = "-&#-&#-&#-&#-Boundary_" . uniqid("b");

        // 送信先
        $from = $this->from;

        // 送信元
        $to = $this->to;

        // サブジェクトをMIMEエンコード
        $subject = i18n_mime_header_encode(i18n_convert($this->subject, "SJIS"));

        // 本文をSJISに
        $body = i18n_convert($this->body, "SJIS");

        // メールハンドラオープン
        if(is_null($this->command)) {
            $this->handler = popen("/usr/sbin/sendmail -f $from $to", "w");
        } else {
            $this->handler = popen("$this->command", "w");
        }

        // ヘッダ
        fputs($this->handler, "MIME-Version: 1.0\n");
        fputs($this->handler, "Content-Type: Multipart/Mixed; boundary=\"$boundary\"\n");
        fputs($this->handler, "Content-Transfer-Encoding:Base64\n");
        fputs($this->handler, "From: $from\n");
        fputs($this->handler, "To: $to\n");
        fputs($this->handler, "Subject: $subject\n");

        // 本文
        fputs($this->handler, "--$boundary\n");
        fputs($this->handler, "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n");
        fputs($this->handler, "\n");
        fputs($this->handler, "$body\n");

        // 添付ファイル
        foreach($this->files as $file) {

            // ファイルチェック
            if(!is_file($file)) break;

            // ベース名取得
            $basename = basename($file);

            // コンテンツ取得
            $attach = file_get_contents($file);
            // 添付データをBASE64エンコード
            $attach = chunk_split(base64_encode($attach));
       
            fputs($this->handler, "--$boundary\n");
            fputs($this->handler, "Content-Type: application/octet-stream; name=\"$basename\"\n");
            fputs($this->handler, "Content-Transfer-Encoding: base64\n");
            fputs($this->handler, "Content-Disposition: attachment; filename=\"$basename\"\n");
            fputs($this->handler, "\n");
            fputs($this->handler, "$attach\n");
            fputs($this->handler, "\n");

        }
        fputs($this->handler, "--$boundary" . "--\n");

        // クローズ
        pclose($this->handler);

        // 返却
        return 0;

    }

    /**
     * Command(Handler)の設定(debug用)
     * 設定したcommandはexecute()で必ずクローズされる。
     * @param    command        command
     */
     function setCommand($command) {
         $this->command = $command;
     }

}

?>

 

使い方は、以下な感じ。

require_once('SendMail.class.php');
$mail =& new SendMail(' このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい ', ' このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい ', 'subject', 'body', '/etc/passwd,/etc/group');
//$mail->setCommand('cat'); // DEBUG用
$mail->execute();

Tag it:
Hatena
Delicious
Spurl
blogmarks

Add as favourites (53) | Quote this article on your site | Views: 17718

  Comments (10)
 1 Comment 01 808
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 01-11-2008 16:08 , IP: 91.121.120.173
http://klzzsas.warszawa.pl your site is so great!
 2 Comment 01 808
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 01-11-2008 16:08 , IP: 91.121.120.173
http://klzzsas.warszawa.pl your site is so great!
 3 Comment 02 1717
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 03-11-2008 01:16 , IP: 91.121.211.187
http://klsas.warszawa.pl your site is so great!
 4 Comment 02 1835
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 03-11-2008 02:35 , IP: 91.121.120.173
http://klsas.warszawa.pl your site is so great!
 5 Comment 02 2103
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 03-11-2008 05:03 , IP: 91.121.120.173
http://klsas.warszawa.pl your site is so great!
 6 Comment 02 2103
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 03-11-2008 05:03 , IP: 91.121.120.173
http://klsas.warszawa.pl your site is so great!
 7 Comment 05 1931
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 06-11-2008 03:31 , IP: 91.121.120.173
[URL=http://groups.google.hu/group/fconeatlsu/web/mother-and-daughter-lesbian-love]Mother And Daughter Lesbian Love 00457[/URL] [URL=http://groups.google.cg/group/s9dziyvx/web/big-boobs-anal-sex]Big Boobs Anal Sex 4f2[/URL] [URL=http://groups.google.lv/group/tmqkgiqofsddvuk/web/extreme-anal-dildo-sex]Extreme Anal Dildo Sex 08cd9[/URL] [URL=http://groups.google.tt/group/c9izgae8dwcs/web/gay-guys-having-sex-with-each-other-naked]Gay Guys Having Sex With Each Other Naked 2606[/URL] [URL=http://groups.google.co.ve/group/cxltt10iorfei/web/hillary-duff-nude-fakes]Hillary Duff Nude Fakes e0ccd8[/URL] [URL=http://groups.google.co.il/group/iwlm0awbnzt0/web/testimony-of-teens-oral-sex]Testimony Of Teens Oral Sex ba89f[/URL] [URL=http://groups.google.com.sa/group/jrixjwbro/web/young-lesbian-kids-photos]Young Lesbian Kids Photos 4035dbc[/URL] [URL=http://groups.google.no/group/eie2jarz/web/listen-to-mixtapes-befor-buying]Listen To Mixtapes Befor Buying 0c434334[/URL] [URL=http://groups.google.am/group/olmaa3n2azim/web/arab-teen-sex]Arab Teen Sex 190b93[/URL] [URL=http://groups.google.fr/group/lvp3vdlxnoihe/web/the-simpsons-cartoons-having-sex]The Simpsons Cartoons Having Sex 3f4[/URL] [URL=http://groups.google.co.ve/group/gt4d0hualh/web/oral-and-maxillofacial-surgeons-conference]Oral And Maxillofacial Surgeons Conference 0b8d491b[/URL] [URL=http://groups.google.com.co/group/u575zjdogxs73am/web/home-made-taboo-sex-movies]Home Made Taboo Sex Movies 69a9b11[/URL] [URL=http://groups.google.tt/group/idiptie2ek/web/free-sex-teacher-tv]Free Sex Teacher Tv 9bb9[/URL] [URL=http://groups.google.lv/group/tmqkgiqofsddvuk/web/teen-lesbian-licking-clit]Teen Lesbian Licking Clit 9a560[/URL] [URL=http://groups.google.com.pa/group/iceidfkg/web/animals-and-and-women-having-sex]Animals And And Women Having Sex b8275[/URL] [URL=http://groups.google.tt/group/c9izgae8dwcs/web/cock-sucking-gay-men]Cock Sucking Gay Men c12[/URL] [URL=http://groups.google.to/group/sc1uaaxxoo/web/milf-ass-n-tits]Milf Ass N Tits 60d815f2[/URL] [URL=http://groups.google.co.za/group/hcvisoo0iyt/web/hot-pussy-ass]Hot Pussy Ass 200fe9c[/URL] [URL=http://groups.google.com.sa/group/0yohkrok9l9r/web/blow-dryers]Blow Dryers 0734c1[/URL] [URL=http://groups.google.tt/group/c9izgae8dwcs/web/free-gospel-listen-music-online]Free Gospel Listen Music Online d639[/URL] [URL=http://groups.google.la/group/83ujqt1h/web/pictures-of-horse-fucking-a-girl-in-ass]Pictures Of Horse Fucking A Girl In Ass ca94093bc[/URL] [URL=http://groups.google.no/group/eie2jarz/web/free-hairy-pussy-fucking]Free Hairy Pussy Fucking 55ecc[/URL] [URL=http://groups.google.co.cr/group/alcfv49e5artp/web/top-10-south-indian-sex]Top 10 South Indian Sex 4e0ca9e[/URL] [URL=http://groups.google.lv/group/tmqkgiqofsddvuk/web/anal-stretching-picstips]Anal Stretching Picstips 45cc[/URL] [URL=http://groups.google.com.sb/group/jnubwbae/web/free-anal-porn-clips-dp]Free Anal Porn Clips Dp 63577[/URL] [URL=http://groups.google.la/group/83ujqt1h/web/free-hardcore-anal-latino-pics]Free Hardcore Anal Latino Pics b4de1[/URL] [URL=http://groups.google.dj/group/vxqha2q44dbl/web/monsters-of-cock-veronica]Monsters Of Cock Veronica 54a[/URL]
 8 Comment 06 001
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 06-11-2008 08:00 , IP: 91.121.120.173
[URL=http://665.galician.az.pl]no money video slots 5163b[/URL] [URL=http://154.chinchillidae.az.pl]cheap flights malaga paris 0b43bf32b[/URL] [URL=http://605.synchronize.az.pl]cheap flights to u.s. virgin islands d3b99f3e9[/URL] [URL=http://649.galician.az.pl]casino slots online 5ae[/URL] [URL=http://550.synchronize.az.pl]cheap flights to montego jamaica 4d8[/URL] [URL=http://510.synchronize.az.pl]flights to kuwait airport 213837[/URL] [URL=http://505.synchronize.az.pl]how to cancel airline tickets online on yatra.com 07e[/URL] [URL=http://303.synchronize.az.pl]flights to u.s. virgin islands from lga 26412fa26[/URL] [URL=http://410.chinchillidae.az.pl]domestic flights in new zealand 5362[/URL] [URL=http://656.chinchillidae.az.pl]easy jet flights to istanbul ea637a9e[/URL] [URL=http://274.synchronize.az.pl]flights from spain 3cf6[/URL] [URL=http://405.synchronize.az.pl]flights to naples italy from ireland 312[/URL] [URL=http://269.chinchillidae.az.pl]flights to orlando, fl in march 2008 b175ef3a8[/URL] [URL=http://633.galician.az.pl]sims fre slots 25d7b[/URL] [URL=http://510.chinchillidae.az.pl]student flights - singapore 58b8[/URL] [URL=http://156.chinchillidae.az.pl]larnaca to uk flights 1f435[/URL] [URL=http://778.synchronize.az.pl]cheap last minute flights trinidad fc2f014[/URL]
 9 Comment 06 002
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 06-11-2008 08:02 , IP: 91.121.120.173
[URL=http://665.galician.az.pl]no money video slots 5163b[/URL] [URL=http://154.chinchillidae.az.pl]cheap flights malaga paris 0b43bf32b[/URL] [URL=http://605.synchronize.az.pl]cheap flights to u.s. virgin islands d3b99f3e9[/URL] [URL=http://649.galician.az.pl]casino slots online 5ae[/URL] [URL=http://550.synchronize.az.pl]cheap flights to montego jamaica 4d8[/URL] [URL=http://510.synchronize.az.pl]flights to kuwait airport 213837[/URL] [URL=http://505.synchronize.az.pl]how to cancel airline tickets online on yatra.com 07e[/URL] [URL=http://303.synchronize.az.pl]flights to u.s. virgin islands from lga 26412fa26[/URL] [URL=http://410.chinchillidae.az.pl]domestic flights in new zealand 5362[/URL] [URL=http://656.chinchillidae.az.pl]easy jet flights to istanbul ea637a9e[/URL] [URL=http://274.synchronize.az.pl]flights from spain 3cf6[/URL] [URL=http://405.synchronize.az.pl]flights to naples italy from ireland 312[/URL] [URL=http://269.chinchillidae.az.pl]flights to orlando, fl in march 2008 b175ef3a8[/URL] [URL=http://633.galician.az.pl]sims fre slots 25d7b[/URL] [URL=http://510.chinchillidae.az.pl]student flights - singapore 58b8[/URL] [URL=http://156.chinchillidae.az.pl]larnaca to uk flights 1f435[/URL] [URL=http://778.synchronize.az.pl]cheap last minute flights trinidad fc2f014[/URL]
 10 Comment 06 622
Written by このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい , on 06-11-2008 14:22 , IP: 91.121.120.173
[URL=http://407.chinchillidae.az.pl]glasgow new york flights 50a[/URL] [URL=http://302.chinchillidae.az.pl]flights turkey cheap 145[/URL] [URL=http://477.galician.az.pl]machine slots 7675815[/URL] [URL=http://722.chinchillidae.az.pl]cheap flights from miami to hartford, ct 88ce3e7eb[/URL] [URL=http://385.chinchillidae.az.pl]cheap flights to turkey in september 020[/URL] [URL=http://483.galician.az.pl]www free casino games fa29fe2[/URL] [URL=http://259.galician.az.pl]wpt online games slots to play for free online ff9a63eff[/URL] [URL=http://692.galician.az.pl]irish slots free downloads b81d6afd5[/URL] [URL=http://356.synchronize.az.pl]cheapest flights to orlando florida a36b7cab[/URL] [URL=http://787.galician.az.pl]charles town races and slots in charles town, west virginia e61e834[/URL] [URL=http://627.synchronize.az.pl]student discount flights to iran 03dc8e[/URL] [URL=http://134.galician.az.pl]practice video slots 6b8b[/URL] [URL=http://298.galician.az.pl]cherry slots games for sale for pc 7fd[/URL] [URL=http://468.chinchillidae.az.pl]expedia low rates for flights 24d2e6[/URL] [URL=http://724.synchronize.az.pl]cheapest discount airline tickets e57b2513b[/URL] [URL=http://476.synchronize.az.pl]cheap flights to ibiza 4dca1[/URL] [URL=http://544.synchronize.az.pl]air flights from ontario airport to las vegas e910[/URL] [URL=http://847.synchronize.az.pl]cheap airline tickets from las vegas to reno c6c4f2a0e[/URL] [URL=http://156.chinchillidae.az.pl]larnaca to uk flights b4570[/URL] [URL=http://10.synchronize.az.pl]cheapest last minute flights to tampa fla. 8f66d7cb1[/URL] [URL=http://679.chinchillidae.az.pl]cheap flights perth to prague dec 13th 2007 52ff4[/URL] [URL=http://305.synchronize.az.pl]booking airline flights on line vs travel agency 359af865[/URL] [URL=http://214.chinchillidae.az.pl]cheap flights going one way 3f147f2[/URL] [URL=http://123.galician.az.pl]charlestown slots age 1e1b2[/URL] [URL=http://646.synchronize.az.pl]qantas flights from london to singapore 59232[/URL] [URL=http://879.synchronize.az.pl]cheap last minute flights with no booking fees 8b72a94[/URL]

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Personal verbal attacks will be deleted.
  • Please don't use comments to plug your web site. Such material will be removed.
  • Just ensure to *Refresh* your browser for a new security code to be displayed prior to clicking on the 'Send' button.
  • Keep in mind that the above process only applies if you simply entered the wrong security code.
Name:
Comment:

Code:* Code

Powered by AkoComment Tweaked Special Edition v.1.4.6
AkoComment © Copyright 2004 by Arthur Konze - www.mamboportal.com
All right reserved

Update ( 2006/10/22 日曜日 23:08 )
 
< 前へ

© 2008 Labs Zsrv Net
Joomla! is Free Software released under the GNU/GPL License.
Translation is Joomla!JAPAN