56日目:sfMailクラスと sendmailで苦闘
お問い合わせフォームを作ろうと思って、sfMailクラスをいろいろやったけどメールがうまく届かない。
でも、メールの送信は成功しているっぽいメッセージが出てくる。
これはどういう事なのだろうと思って、sfMailじゃなくて、mb_send_mail関数で直接やっても OKの返事がでます。そこで調べて見ると、ここ↓の「おまけ」のところに、重要な事が書いてありました。
>(オマケ)
>PHPからメールを送るときはphp.iniで
>sendmail_pathの設定がされていなければなりません。
>もしお使いのサーバでメールが送れなかったら
>サーバ管理者に問い合わせみてくださいね。
sendmail_pathを設定するという事は、sendmailが動いていないといけないわけです。ああ、sendmailの設定をしないと駄目なんですね。要するに sfMailクラスや mb_send_mail関数は、sendmailを呼び出しているだけだったのです。phpってメールを簡単に送れてすごいなーと思ってたのですが、そういう事だったのか(それでもありがたいけど)。
という訳で、数時間の私的リサーチ時間の後、sendmailの設定をすればよさそうだと分かりましたので、作業を開始しました。例によってここが先生です。
セキュリティーの設定ですが、とりあえず送信のみができればよいので、外部から 25番ポートにアクセスがあっても、サーバに転送しないようにルータを設定してあります。これで smtp-authとかの面倒くさい設定は省略する事ができると思うのですが、良いですよね?
とりあえず、初期設定で sendmailはインストールされていたので、あとは設定するだけのはず。
とやっても動いているっぽいです。rootと userの間でメールを送る事ができました。という事で、いろいろ設定していきました。そして、メール送信。
$ echo hogeaiueo | mail -s sample uchida@mymail.jp
送れたかな? と思ったのですが、
とすると、エラーでメールが戻ってきています。
うまく動かないのでまたもや悪戦苦闘。
とりあえず、OP25B(Outbound Port 25 Blocking)対策をチェックしてみました。
あれ、うちのプロバイダは素通りです。対策する手間がはぶけました。
自分が持っているあちこちのメールアドレスにメールを送ると、アドレスごとに違うエラーメッセージが帰ってくるので、とりあえず、社内LANの外にメールが出て行っているのは間違いない。という事は、外部のメールサーバに拒否されているという事ですが、なんで拒否されるんだろうと。インターネットの世界で1人仲間はずれ状態です。
ここでまた数時間、私的リサーチの時間になってしまいました。
いろいろ調べてもちっとも分からなかったのですが、ふと、dnsの mxレコードを設定していないからではないかと思いつきました。いや、送信したいだけなんですが、設定する必要あるんでしょうか? まぁとにかくやってみようというわけで、やってみました。
mx @ 10 a @ 118.6.196.47
やってみたけど、変化なし。dnsの浸透に時間がかかるんでしょう。というわけで一旦、家に帰って寝ることにしました。
〜〜〜〜〜〜〜〜〜〜〜〜
というわけで、起きました。というか、知り合いから電話がかかってきて起こされました。うー。
早速、メールを送ってみました。
$ echo hogeaiueo | mail -s sample uchida@mymail.jp
おお、ちゃんと送れているみたいです。とりあえず、普段使っている2つのメールアドレスには送れました。
が、hotmailには送れません。こんなエラーが帰ってきました。
$ echo hogeaiueo | mail -s sample mymail@hotmail.com $ mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/sido": 1 message 1 new >N 1 MAILER-DAEMON@podtvl Wed May 28 04:11 65/3318 "Returned mail: see transcript f" & Message 1: From MAILER-DAEMON@podtvlabo.com Wed May 28 04:11:42 2008 Date: Wed, 28 May 2008 04:11:42 +0900 From: Mail Delivery Subsystem <MAILER-DAEMON@podtvlabo.com> To: <sido@podtvlabo.com> MIME-Version: 1.0 Content-Type: multipart/report; report-type=delivery-status; boundary="m4RJBgdC005122.1211915502/podtvlabo.com" Subject: Returned mail: see transcript for details Auto-Submitted: auto-generated (failure) This is a MIME-encapsulated message --m4RJBgdC005122.1211915502/podtvlabo.com The original message was received at Wed, 28 May 2008 04:11:42 +0900 from localhost.localdomain [127.0.0.1] ----- The following addresses had permanent fatal errors ----- <mymail@hotmail.com> (reason: 550 DY-001 Mail rejected by Windows Live Hotmail for policy reasons. We gener ally do not accept emai...l/network admins, please visit http://postmaster.live.com for em ail delivery information and support) ----- Transcript of session follows ----- ... while talking to mx2.hotmail.com.: >>> MAIL From:<sido@podtvlabo.com> SIZE=520 <<< 550 DY-001 Mail rejected by Windows Live Hotmail for policy reasons. We generally do n ot accept email from dynamic IP's as they are not typically used to deliver unauthenticate d SMTP e-mail to an Internet mail server. http://www.spamhaus.org maintains lists of dynam ic and residential IP addresses. If you are not an email/network admin please contact your E-mail/Internet Service Provider for help. Email/network admins, please visit http://post master.live.com for email delivery information and support 554 5.0.0 Service unavailable --m4RJBgdC005122.1211915502/podtvlabo.com Content-Type: message/delivery-status Reporting-MTA: dns; podtvlabo.com Received-From-MTA: DNS; localhost.localdomain Arrival-Date: Wed, 28 May 2008 04:11:42 +0900 Final-Recipient: RFC822; mymail@hotmail.com Action: failed Status: 5.0.0 Diagnostic-Code: SMTP; 550 DY-001 Mail rejected by Windows Live Hotmail for policy reasons . We generally do not accept email from dynamic IP's as they are not typically used to del iver unauthenticated SMTP e-mail to an Internet mail server. http://www.spamhaus.org maint ains lists of dynamic and residential IP addresses. If you are not an email/network admin please contact your E-mail/Internet Service Provider for help. Email/network admins, pleas e visit http://postmaster.live.com for email delivery information and support Last-Attempt-Date: Wed, 28 May 2008 04:11:42 +0900 --m4RJBgdC005122.1211915502/podtvlabo.com Content-Type: message/rfc822 Return-Path: <sido@podtvlabo.com> Received: from podtvlabo.com (localhost.localdomain [127.0.0.1]) by podtvlabo.com (8.13.8/8.13.8) with ESMTP id m4RJBgdC005120 for <mymail@hotmail.com>; Wed, 28 May 2008 04:11:42 +0900 Received: (from sido@localhost) by podtvlabo.com (8.13.8/8.13.8/Submit) id m4RJBg2N005119 for mymail@hotmail.com; Wed, 28 May 2008 04:11:42 +0900 Date: Wed, 28 May 2008 04:11:42 +0900 From: sido@podtvlabo.com Message-Id: <200805271911.m4RJBg2N005119@podtvlabo.com> To: mymail@hotmail.com Subject: sample hogeaiueo --m4RJBgdC005122.1211915502/podtvlabo.com--
どうも ダイナミックIPだと、受け付けてあげないよーと書いてあるようです。あー、開発用サーバーも固定IPにしないのいけないんでしょうかね?
ついでに Gmailもテスト。
$ echo hogeaiueo | mail -s sample mymail@gmail.com $ mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/sido": 1 message 1 new >N 1 MAILER-DAEMON@podtvl Wed May 28 04:18 69/2577 "Returned mail: see transcript f" & Message 1: From MAILER-DAEMON@podtvlabo.com Wed May 28 04:18:05 2008 Date: Wed, 28 May 2008 04:18:05 +0900 From: Mail Delivery Subsystem <MAILER-DAEMON@podtvlabo.com> To: <sido@podtvlabo.com> MIME-Version: 1.0 Content-Type: multipart/report; report-type=delivery-status; boundary="m4RJI5qR005145.1211915885/podtvlabo.com" Subject: Returned mail: see transcript for details Auto-Submitted: auto-generated (failure) This is a MIME-encapsulated message --m4RJI5qR005145.1211915885/podtvlabo.com The original message was received at Wed, 28 May 2008 04:18:00 +0900 from localhost.localdomain [127.0.0.1] ----- The following addresses had permanent fatal errors ----- <mymail@gmail.com> (reason: 550-5.7.1 [118.6.196.47] The IP you're using to send mail is not authorized) ----- Transcript of session follows ----- ... while talking to gmail-smtp-in.l.google.com.: >>> DATA <<< 550-5.7.1 [118.6.196.47] The IP you're using to send mail is not authorized <<< 550-5.7.1 to send email directly to our servers. Please use the SMTP <<< 550-5.7.1 relay at your service provider instead. Learn more at <<< 550 5.7.1 http://mail.google.com/support/bin/answer.py?answer=10336 24si4447164wff.12 554 5.0.0 Service unavailable --m4RJI5qR005145.1211915885/podtvlabo.com Content-Type: message/delivery-status Reporting-MTA: dns; podtvlabo.com Received-From-MTA: DNS; localhost.localdomain Arrival-Date: Wed, 28 May 2008 04:18:00 +0900 Final-Recipient: RFC822; mymail@gmail.com Action: failed Status: 5.7.1 Remote-MTA: DNS; gmail-smtp-in.l.google.com Diagnostic-Code: SMTP; 550-5.7.1 [118.6.196.47] The IP you're using to send mail is not au thorized Last-Attempt-Date: Wed, 28 May 2008 04:18:05 +0900 --m4RJI5qR005145.1211915885/podtvlabo.com Content-Type: message/rfc822 Return-Path: <sido@podtvlabo.com> Received: from podtvlabo.com (localhost.localdomain [127.0.0.1]) by podtvlabo.com (8.13.8/8.13.8) with ESMTP id m4RJI0qR005143 for <mymail@gmail.com>; Wed, 28 May 2008 04:18:00 +0900 Received: (from sido@localhost) by podtvlabo.com (8.13.8/8.13.8/Submit) id m4RJI07b005142 for mymail@gmail.com; Wed, 28 May 2008 04:18:00 +0900 Date: Wed, 28 May 2008 04:18:00 +0900 From: sido@podtvlabo.com Message-Id: <200805271918.m4RJI07b005142@podtvlabo.com> To: mymail@gmail.com Subject: sample hogeaiueo --m4RJI5qR005145.1211915885/podtvlabo.com--
あらー、こちらもエラーです。
おいおい、直接うちの smtpサーバにメールを出すんじゃなくて、プロバイダのサーバを経由してから送ってこいよ、って書いてあるみたいです。
メール出すのも、なかなか大変ですね。