pearのMailライブラリがうまくいきません

このQ&Aのポイント
  • 空メール登録のシステムを作っています。スクリプト以前に、メールを送ると「Fw:Returned mail: see transcript for details」のタイトルで以下のような文章でかえってきます。
  • aliasesの設定には以下のようにしています。sendmail, postfixはインストールされています。
  • スクリプトはPEAR::MailライブラリとPEAR::Mail_mimeライブラリを使用しています。メールソースを読み込み、メールを解析し、送信元を取得してから、送信データを設定し、メールを送信します。
回答を見る
  • ベストアンサー

pearのMailライブラリがうまくいきません

自分で解決できなかったので、申し訳ないですが他力本願させていただきます。 空メール登録のシステムを作っています。 スクリプト以前に、メールを送ると 「Fw:Returned mail: see transcript for details」のタイトルで 以下のような文章でかえってきます。 rom: Mail Delivery Subsystem <MAILER-DAEMON@www.abc.com> Date: Fri, 23 Jan 2009 19:15:27 +0900 To: <hoge@ezweb.ne.jp> Subject: Returned mail: see transcript for details The original message was received at Fri, 23 Jan 2009 19:15:27 +0900 from xxxxxxxxxx.ezweb.ne.jp [11.111.11.123] ----- The following addresses had permanent fatal errors ----- "|php /var/www/hoge-html/hogehoge/empty_mail.php" (reason: Service unavailable) (expanded from: <hohogege@hoge.jp>) ----- Transcript of session follows ----- smrsh: "empty_mail.php" not available for sendmail programs (stat failed) 554 5.0.0 Service unavailable aliasesの設定には以下のようにしています。パスはあっています。 hohogege:"|php /var/www/hoge-html/hogehoge/empty_mail.phpp" sendmail, postfixはインストールされています。 ちなみにスクリプトは以下のように書きました。 //PEAR::Mailライブラリ require_once 'Mail.php'; //PEAR::Mail_mimeライブラリ require_once '/usr/share/pear/Mail/mimeDecode.php'; //メールソースを読み込む $source = file_get_contents("php://stdin"); if(!souce){ exit(); } //メールを解析する。 $decoder = new Mail_mimeDecode($source); $structure = $decoder->decode($params); //送信元を取得する。 $form = $structure->headers['from']; $form = mb_decode_mimeheader($from); $form = mb_convert_encoding($form, mb_internal_encoding(), 'auto'); if(preg_match( '/<(.*?)>$/', $from, $match)){ $from = $match[1]; } $from = trim($from); $from = strtolower($from); //送信データを設定する $recipients = $from; $new_from = 'hogehoge@abc.jp'; $subject = 'empty mail ok'; $body = 'http://www.hogehoge.jp'; //メールを送信する $headers = array(); $headers['From']=$new_from; $headers['To']=$recipients; $headers['Subject']=$subject; $headers['Sender']=$new_from; $mail = Mail::factory('sendmail'); $result = $mail->send($recipients, $headers, $body);

  • PHP
  • 回答数1
  • ありがとう数1

質問者が選んだベストアンサー

  • ベストアンサー
  • tany180sx
  • ベストアンサー率63% (239/379)
回答No.1

・メールログを確認する。 ・phpをフルパスに変更する。 ・hohogegeを確認する。

future-boy
質問者

お礼

ありがとうございます。 SMTPサーバーの設定がおかしかったもようです。

関連するQ&A

  • Xserverでの空メール実装について

    Xserverで空メールを実装しようとしています。 しかしうまく動作しません。 マニュアルを参考に「メールの振り分け設定」より 条件:あて先が ○○○○○@△△△△ を一致する 処理方法:| /○○○○/□□□□/sippai.php へ 転送する としました。 しかし、携帯電話より○○○○○@△△△△へメール送信しても、 差出人:MAILER-DAEMON@△△△.xserver.jp 件名:Undelivered Mail Returned to Sender と返信されてしまいます。 サーバー側の設定が何か必要なのでしょうか? スクリプトを以下に記載します。 使用スクリプト;PHP5、ライブラリ;PEAR <?php //PEAR::MailCu require_once '/aaaaaa/bbbb/cccc/ddddd/eeeee/fff/Mail.php'; //PEAR::Mail_mimeCu require_once '//aaaaaa/bbbb/cccc/ddddd/eeeee/ggg/mimeDecode.php'; //メールソースを読み込む $source = file_get_contents("php://stdin"); if(!$source){ exit(); } //メールを解析する $decoder = new Mail_mimeDecode($source); $structure = $decoder->decode($params); //送信元を取得する $from = $structure -> headers['from']; $from = mb_decode_mimeheader($from); $from = mb_convert_encoding($from, mb_internal_encoding(),'auto'); if(preg_match( '/<(.*?)>$/' , $from , $match)){ $from = $match[1]; } $from = trim($from); $from = strtolower($from); //送信データを設定する $recipients = $from; $new_from = '○○○○○@△△△△'; $subject = 'empty mail ok!'; $body = 'http://fmob.jp'; //メールを送信する $headers = array(); $headers['From'] = $new_from; $headers['To'] = $recipients; $headers['Subject'] = $subject; $headers['Sender'] = $new_from; $mail = Mail::factory('sendmail'); $result = $mail->send($recipients, $headers, $body); ini_set('log_errors', '1'); ini_set('error_log', 'エラーログのパス'); ?> よろしくお願いします。

    • ベストアンサー
    • PHP
  • PHP foreachを使ってループしたい

    こんばんは。 PHPで複数の宛先でメールを送信したいと思っております。 そこでメールフォームでまず mail.php foreach ($arr as $value) { print'<input type="hidden" name="mail[]" value="'. $value .'">'; } f-mail.php $_POST['mail']で取得しそれを$valとして、print_r($val);で表示すると Array ( [0] => アドレスA [1] =>アドレスB ) と表示されます。 その複数のアドレスを //PEAR::MailCu require_once '/Mail.php'; //PEAR::Mail_mimeCu require_once '/mimeDecode.php'; //送信データを設定する $recipients= $val; $new_from = 'hoge@hoge.com'; $subject = mb_encode_mimeheader(mb_convert_encoding("$subject1", "JIS", "auto"), "JIS"); $body =$body1; //メールを送信する $headers = array(); $headers['From'] = $new_from; $headers['To'] = $recipients; $headers['Subject'] = $subject; $headers['Sender'] = $new_from; $mail = Mail::factory('sendmail'); $result = $mail->send($recipients, $headers, $body); ・LoopでToを変更しながら繰り返し送信する事がしたいのですがforeachでどう設定していいかわかりません。マニュアルもみたのですが、混乱してしまったので ご指導、ご教授のほど宜しくお願い致します。

    • 締切済み
    • PHP
  • 携帯からの空メールの処理

    こんにちは。今、PHP5.3で、携帯からの空メールを処理するプログラムを作っています。 具体的には、空メールが携帯から送られてくると、エイリアスでPHPプログラムに渡し、送信者に自動返信するというプログラムです。 現在、以下のようなプログラムを作っていますが、うまく動きません。 ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー <?php require_once("/opt/lampp/lib/php/PEAR.php"); // PEAR::Mailライブラリ require_once("/opt/lampp/lib/php/Mail.php"); // PEAR::Mail_mimeライブラリ require_once("/opt/lampp/lib/php/Mail/mimeDecode.php"); $params['include_bodies'] = false; $params['decode_bodies'] = false; $params['decode_headers'] = true; $params['input'] = file_get_contents("php://stdin"); $params['crlf'] = "\r\n"; //メールを解析する $structure = Mail_mimeDecode::decode($params); print_r($structure); //送信元を取得する $mail = $structure->headers['from']; $mail = addslashes($mail); $mail = str_replace('"','',$mail); preg_match("/<.*>/", $mail,$str); if($str[0]!=""){ $str=substr($str[0],1,strlen($str[0])-2); } $mail = $str; //送信データを設定する $recipients = $mail; $new_from = 'register@7ws.jp'; $subject = 'empty mail OK!'; $body ='登録が完了しました。'; $headers = "From:".$new_from; //メールを送信する $headers = array(); $headers['From'] = $new_from; $headers['To'] = $recipients; $headers['Subject'] = $subject; $headers['Sender'] = $new_from; $mail = Mail::factory('sendmail'); $result = $mail->send($recipients, $headers, $body); ?> ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー 参考にしたのは、http://www.phppro.jp/phptips/archives/vol35/1 と「PHP×携帯サイト デベロッパーズバイブル」です。 プログラムを実行しても、空メールの送信者のアドレスが取得できず、 送り先を空白のまま、メールを送信していまい、エラーとなります。 正常に送信者アドレスを取る方法をご存知の方が、いらっしゃいましたら、ご教授お願いします。 なお、$structure = Mail_mimeDecode::decode($params);の下で、 print_r($structure);を実行したところ、 print_r($structure); ( [headers] => Array ( [] => ) [ctype_primary] => text [ctype_secondary] => plain ) という表示なっていました。headersがArrayなのに空っぽなところに、 問題があるのではないかと思います。以上、よろしくお願いします。

    • ベストアンサー
    • PHP
  • PHP5での空メールが実行されない

    現在PHP5を利用して携帯の空メールを実装しており、3日ほどトライし続けておりますが、携帯側にエラーが返信される所で先に進めずにいます(;;)プログラムは勉強し始めて4ヶ月程度の未熟者です。どなたか是非ご教授頂ければと思います。よろしくお願いします!! ちなみに、pearは使えているのを、他のライブラリで確認しました。 【使用言語とライブラリ】 PHP5、pearの『Mail.php』『mimeDecode.php』 【参考書籍】 PHP携帯 デベロッパーズバイブル 【利用サーバー】 Xサーバー 【メールの振り分け設定】 『条件』あて先が ○○○@△△.com を一致する 『処理方法』 | /home/サーバーID/ドメイン/public_html/フォルダ名/フォルダ名/empty_mail.php へ 転送する 【PHPのソース】 #!/usr/bin/php5 <?php //PEAR::Mailライブラリ ini_set('include_path', '/home/サーバーID/ドメイン/public_html/pear/PEAR'); require_once 'Mail/Mail.php'; //PEAR::Mail_mimeライブラリ ini_set('include_path', '/home/サーバーID/ドメイン/public_html/pear/PEAR'); require_once 'Mail/mimeDecode.php'; //メールソースを読み込む $source = file_get_contents("php://stdin","r"); if(!$source){ exit("標準入力に失敗"); } //メールを解析する $decoder = new Mail_mimeDecode($source); $structure = $decoder->decode($params); //送信元を取得する $from = $structure -> headers['from']; $from = mb_decode_mimeheader($from); $from = mb_convert_encoding($from, mb_internal_encoding(),'auto'); if(preg_match( '/<(.*?)>$/' , $from , $match)){ $from = $match[1]; } $from = trim($from); $from = strtolower($from); //送信データを設定する $recipients = $from; $new_from = ○○○@△△.com'; $subject = 'empty mail ok!'; $body = '(仮)こんにちわ'; //メールを送信する $headers = array(); $headers['From'] = $new_from; $headers['To'] = $recipients; $headers['Subject'] = $subject; $headers['Sender'] = $new_from; $mail = Mail::factory('sendmail'); $result = $mail->send($recipients, $headers, $body); ini_set('log_errors', '1'); ini_set('error_log', 'エラーです'); 【エラー内容(すごく長いですが…)】 This is the Postfix program at host sv225.xserver.jp. I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below. For further assistance, please send mail to <postmaster> If you do so, please include this problem report. You can delete your own text from the attached returned message. The Postfix program <○○○@△△.com>: Command died with status 255: "/usr/bin/maildrop". Command output: PHP Warning: require_once(/home/サーバーID/ドメイン名/public_html/pear/PEAR/Mail/Mail.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /home/サーバーID/ドメイン名/public_html/mobile_search/gotempty_mail2.php on line 7 PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/home/サーバーID/ドメイン名/public_html/pear/PEAR/Mail/Mail.php' (include_path='home/サーバーID/ドメイン名/public_html/pear/PEAR') in /home/サーバーID/ドメイン名/public_html/mobile_search/gotempty_mail2.php on line 7 X-Powered-By: PHP/5.1.6_ Content-type: text/html_ _ とても煩雑でごめんなさい(;;) どうかよろしくお願いします。

    • ベストアンサー
    • PHP
  • pear:Mailを使用してのメールフォーム

    Mac OS X 10.7.2 PHPを使用して、メールフォームを作りたいのですが、以下を実行すると 【ソース】 <?php require_once "Mail.php"; $params = array( "host" => "smtp.gmail.com", "port" => 587, "auth" => true, "username" => "ユーザー", "password" => "パスワード" ); $mailObject = Mail::factory("smtp", $params); $recipients = "xxxx@gmail.com"; $headers = array( "To" => "xxxx@gmail.com", "From" => "xxxx@gmail.com", "Subject" => mb_encode_mimeheader("テストメール") ); $body = "日本語メールのテストです。"; $body = mb_convert_encoding($body, "ISO-2022-JP", "auto"); $mail = $mailObject -> send($recipients, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> 【エラー】 Fatal error: Call to undefined method PEAR_Error::send() in /home/u327035945/public_html/send.php on line 56 となってしまいます。 PHP、PEARのインストールをし、Pear::Mailのファイルを、上のソースファイルと同じフォルダにいれ、サーバーにあげました。 PHPを初めて挑戦したので、どこの時点に問題があるのかもわかりません、、、、 よろしくお願いします。

    • ベストアンサー
    • PHP
  • Mail_mimeDecodeでメール本文取得

    index.php <form action="mailto:info@hoge.com" method="get" id="join"> <input type="hidden" name="body" value="<?php echo $friend;?>" /> </center></form> empty_mail.php $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; $params['input'] = file_get_contents("php://stdin"); $params['crlf'] = "\r\n"; $mail_data = Mail_mimeDecode::decode($params); $MailBody = getbody($mail_data); if (!$MailBody) { print "cannot get MailBody"; // エラー処理 }// $MailBodyを使った処理 function getbody($arg) { if ($arg->ctype_primary == 'multipart') { foreach($arg->parts as $parts) { $ret = getbody($parts); if ($ret) { return $ret; } } } if ($arg->ctype_primary == 'text') { if ($arg->ctype_secondary == 'plain') { if (strtolower($arg->ctype_parameters['charset']) == 'iso-2022-jp') { return mb_convert_encoding($arg->body, "UTF-8", 'JIS'); } else { return $arg->body; } } } return false; } //メールを解析する $decoder = new Mail_mimeDecode($source); $structure = $decoder->decode($params); //送信元を取得する $mail = $structure->headers['from']; $mail = addslashes($mail); $mail = str_replace('"','',$mail); $from = $structure -> headers['from']; $from = mb_decode_mimeheader($from); $from = mb_convert_encoding($from, mb_internal_encoding(),'auto'); if(preg_match( '/<(.*?)>$/' , $from , $match)){ $from = $match[1]; } $from = trim($from); $from = strtolower($from); //送信データを設定する $recipients = $from; $new_from = 'info@hoge.com'; mb_language('ja'); mb_internal_encoding('sjis'); $subject = mb_encode_mimeheader(mb_convert_encoding("登録URL", "JIS", "auto"), "JIS"); $body = "下記のURLをクリックして登録を行ってください http://hoge/hoge.php?". $MailBody . "". session_name()."=". htmlspecialchars(session_id()); と$friendを登録フォーム画面にいくまで情報を維持したいのですが、ご教授お願いします。

    • ベストアンサー
    • PHP
  • PEAR::Mail のシステム環境

    PEAR::Mailを使用しプロバイダのメールサーバ経由でPHPモジュールよりPC端末、携帯にメール送信できるようにしたいです。 OS:WindowsServer2003 Apache、PHP(PEAR導入済み)、Postgresql 現在OB25pという制度が各プロバイダで設定されており、個人メールサーバからメールが送信できない仕様になりました。 認証を行えば使えるということで、PEARの導入を考えました。 PEARを導入して、以下のプログラムで送信かけたのですがPC端末、携帯端末にも送信されない状態です。 $params["host"] = "smtp.mail.yahoo.co.jp"; $params["auth"] = true; $params["username"] = "username"; $params["password"] = "password"; $sender = "from@example.com"; $recipient = "to@example.org"; *メッセージ省略* require_once 'Mail.php'; $smtp = Mail::factory("smtp", $params); if (PEAR::isError($smtp)) die($smtp->getMessage()); $headers['From'] = $sender; $headers['Subject'] = $subject; $headers['Content-Transfer-Encoding'] = "8bit"; $headers['X-Mailer'] = "PHP PEAR/Mail(smtp)"; $smtp->send($recipient, $headers, $message); if (PEAR::isError($smtp)) die($smtp->getMessage()); exit("メッセージを送信しました"); ちなみにプロバイダはYahoo!BBです。 質問です。 ・上記のプログラムより直接Yahoo!BBのメールサーバに投げようとしているのですが問題ないでしょうか?自サーバよりWindowsコンポーネントのIIS(SMTP)経由の方がよろしいでしょうか?またその時の設定はどうするのでしょうか? ・自サーバにはDNSはたててない状態なのですが、問題ないでしょうか? 他に問題事項がございましたらご指摘願います。 長々とすみませんが、何卒よろしくお願いいたします。

    • 締切済み
    • PHP
  • メールのFromに半角ピリオドが入るとエラーが・・・

    PEARのメール送信について教えてください。 現在PEARのMailと、mime.phpを使用してメール送信をするプログラムを組んでいるのですが、エンコードの仕方が悪いのかメールのFromに半角ピリオド、半角カンマなどが入るとエラーが出てしまいます。 以下がそのコードの主要部分ですが、対応策がありましたらご教授ください。よろしくお願いいたします。 --------------------------------------------------------- //ヘッダーのFromエンコード(問題の部分?) $headers['From'] = mb_encode_mimeheader(mb_convert_encoding( $mail_from_name , "ISO-2022-JP", "EUC-JP"))."<".$mail_from.">"; $objMail =& Mail::factory('sendmail'); $original = mb_internal_encoding(); $headers['Subject'] = mb_convert_encoding( $sbj , "ISO-2022-JP" , "EUC-JP" ); mb_internal_encoding("ISO-2022-JP"); $headers['Subject'] = mb_encode_mimeheader($headers['Subject'],"ISO-2022-JP"); mb_internal_encoding($original); $crlf = "\n"; $mime =& new Mail_mime($crlf); $mime->setHTMLBody($body); $build_param = array( "html_charset" => "EUC-JP", "text_charset" => "ISO-2022-JP", "head_charset" => "ISO-2022-JP", ); $body = $mime->get( $build_param ); $headers = $mime->headers($headers); $objMail =& Mail::factory('sendmail'); $result = $objMail->send( $mail_to , $headers , $body );

    • 締切済み
    • PHP
  • エックスサーバーで 空メール実行PHP

    エックスサーバーを借りています。 PHPの勉強を始めたばかりの初心者です。 空メールを送り、定型文を自動返信させたいのですが、うまくいきません。 どなたか何処が間違っているのが、教えていただけないでしょうか? 《設定内容》 エックスサーバーのメール振り分けは、 条件(キーワード)  ○○○@△△.△△△.jp 条件(場所)     あて先 条件(一致)     内容を含む 処理方法       | /usr /bin/php5 /home/サーバーID/ドメイン/public_html/empty_mail.php 【.htaccess】 php_value register_globals 1 php_value magic_quotes_gpc 0 php_value session.use_cookies 0 php_value session.use_trans_sid 0 php_value output_buffering 1 php_value output_handler mb_output_handler php_value default_charset EUC-JP php_value mbstring.language Japanese php_value mbstring.internal_encoding EUC-JP php_value mbstring.http_input EUC-JP php_value mbstring.http_output EUC-JP php_value mbstring.encoding_translation 1 php_value mbstring.detect_order auto php_value mbstring.substitute_character none 【php.ini】 safe_mode = off max_input_time = 60 output_buffering = none safe_mode_exec_dir = none upload_max_filesize = 10M variables_order = EGPCS dbx.colnames_case = lowercase HTTP input encoding translation = on mbstring.detect_order = auto mbstring.encoding_translation = on mbstring.http_input = auto mbstring.http_output = SJIS mbstring.internal_encoding = EUC-JP mbstring.language = Japanese session.save_path = /var/lib/php/session url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry" 【empty_mail.php】 #!/usr/bin/php5 <?php require_once 'Mail/mail.php'; require_once 'Mail/mimeDecode.php'; $source = file_get_contents("php://stdin"); if(!$source){ exit(); } $decoder = new Mail_mimeDecode($source); $structure = $decoder->decode($params); $from = $structure->headers['from']; $from = mb_decode_mimeheader($from); $from = mb_convert_encoding($from, mb_internal_encoding(), 'auto'); if (preg_match( '/<(.*?)>$/', $from, $match) { $from = $match[1]; } $from = trim($from); $from = strtolower($from); $recipients = $from; $new_from = '○○○@△△.△△△.jp'; $subject = '=='; $body = '===本文===='; $headers = array(); $headers['From'] = $new_from; $headers['To'] = $recipients; $headers['Subject'] = $subject; $headers['Sender'] = $new_from; $mail = Mail::factory('sendmail'); $result = $mail->send($recipients, $headers, $body); ini_set('log_errors', '1'); ini_set('error_log', 'エラーログのパス'); ?> 【携帯へ帰ってきたエラー内容】 This is the Postfix program at host sv○○○.xserver.jp. I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below. For further assistance, please send mail to <postmaster> If you do so, please include this problem report. You can delete your own text from the attached returned message. The Postfix program <○○○@△△.△△△.jp>: Command died with status 126: "/usr/bin/maildrop". Command output: sh: /usr: is a directory 問題だらけだと思うのですが、どこをどう直していいのか わかりません。お願いします。

    • 締切済み
    • PHP
  • SMTP接続でのPEARメール送信の差出人がsoftbankのみ表示さ

    SMTP接続でのPEARメール送信の差出人がsoftbankのみ表示されなくて困っております。 require_once("Mail.php"); require_once("Mail/mimeDecode.php"); mb_internal_encoding('UTF-8'); mb_language("ja"); $params = array( "host" => "***", "port" => 587, "auth" => true, "username" => "***", "password" => "***" ); $mailObject = Mail::factory("smtp", $params); $internal = 'utf-8'; $input = 'utf-8'; $target = 'ISO-2022-JP'; $recipients = "hoge@hoge.com"; $from_name = "日本語"; $from_name = mb_convert_encoding($from_name,$input,mb_detect_encoding($from_name)); $subject = "テスト"; $subject = mb_convert_encoding($subject,$input,mb_detect_encoding($subject)); $headers = array( "To" => $from, "From" => mb_encode_mimeheader($from_name,$target)."<***>", "Subject" => mb_encode_mimeheader($subject,$target), "Return-Path" => mb_encode_mimeheader($subject,$target)."<***>", ); $body = "テスト"; $body = mb_convert_encoding($body,$target,mb_detect_encoding($body)); $mailObject -> send($recipients, $headers, $body); なかなか説明が難しいので、手っ取り早くコードを書き出しましたが、 このphpファイルを使ってメールを送信しますと、 PCメール、WEBメール(hotmail)、携帯メール(DOCOMO,AU,SOFTBANK) 全て文字化けなく送信出来ている状況です。 上記のうち、差出人が受信側で表示されるのはDOCOMO以外全てだと思うのですが、 (もちろん携帯は機種によっては例外的に表示されないのもあるかと) 他のPCメールからは日本語の差出人が確認できるSOFTBANK機種でメールを 受信しますと、(差出人が設定されていない場合と同じ)メールアドレスのみが 表示されてしまう状態です。 前述のphpファイルは、SOFTBANK以外の差出人設定可能なPC,WEB,AUは 全て差出人の設定が確認できております。その問題のSOFTBANKも、差出人が 設定されないだけで、件名本文ともに文字化けせず、正常に受信が出来ています。 ネットで色々と探してみましたが、同様の状況が確認できず、 どなたかお力添えいただけましたら幸いかと思い、質問した次第です。 どうかよろしくお願いいたします。

    • 締切済み
    • PHP

専門家に質問してみよう