質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Postfix

Postfixは、電子メールサーバソフトウェアで、 メールを配送するシステムMTAの一種です。

サーバ

サーバは、 クライアントサーバモデルにおいてクライアントからの要求に対し 何らかのサービスを提供するプログラムを指す言葉です。 また、サーバーソフトウェアを稼動させているコンピュータ機器そのもののことも、 サーバーと呼ぶ場合もあります。

Q&A

解決済

2回答

5022閲覧

PHPでのメール送信ができない

sug1t0m0

総合スコア40

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Postfix

Postfixは、電子メールサーバソフトウェアで、 メールを配送するシステムMTAの一種です。

サーバ

サーバは、 クライアントサーバモデルにおいてクライアントからの要求に対し 何らかのサービスを提供するプログラムを指す言葉です。 また、サーバーソフトウェアを稼動させているコンピュータ機器そのもののことも、 サーバーと呼ぶ場合もあります。

0グッド

0クリップ

投稿2016/01/13 02:42

編集2016/01/13 08:19

Postfixを使ってPHPからメールの送信を行いたいのですが、うまくいきません。

[http://www.seekcloud.co.jp/blog/memorandum/254]
を参考にメールサーバーの設定をしました。アカウント名とパスワードをGmailのものに変更しました。エラーログには「defer service failure」や「Operation time out」と書いてあります。

Gmailアカウントを使用していることがいけないのでしょうか?
どうしてメールが送信されないのか分かりません。どなたかお助けください。

最終的には、WordPressのContact Form 7というプラグインを作って問い合わせ内容をメールで受信できるようにする予定ですが、もっといい方法があったら教えていただけると助かります。

----以下Postfixの設定の詳細です----

Postfixを使用してGmailアカウントからメールを送信したいのですがOperation timed outになってしまいます。
参考にしたURLは
http://www.storange.jp/2012/01/php.html
http://www.seekcloud.co.jp/blog/memorandum/254

です。
Postfixの設定手順としては、まず

sudo vi /etc/postfix/sasl_passwd

コマンドで

smtp.gmail.com:587 Gmaiアカウントのユーザー名@gmail.com:パスワード

という内容の /etc/postfix/sasl_passwd を作成し

sudo postmap /etc/postfix/sasl_passwd

コマンドで設定を有効化しました。 /etc/postfix/main.cfの設定では

sudo vi /etc/postfix/main.cf

コマンドで /etc/postfix/main.cf の最下段に

# Minimum Postfix-specific configurations. #mydomain_fallback = localhost mail_owner = _postfix setgid_group = _postdrop relayhost=smtp.gmail.com:587 # Enable SASL authentication in the Postfix SMTP client. smtp_sasl_auth_enable=yes smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd smtp_sasl_security_options= noanonymous smtp_sasl_mechanism_filter = plain # Enable Transport Layer Security (TLS), i.e. SSL. smtp_use_tls=yes smtp_tls_security_level=encrypt tls_random_source=dev:/dev/urandom

を追加しました。

sudo postfix start

および

sudo postfix reload

コマンドでPostfixをリフレッシュし

date | mail -s test 自分のユーザー名@gmail.com

コマンドで送信テストを行ったところ、送信済みメールにも受信トレイにもコマンドの結果が反映されていませんでした。下記が

cat /var/log/mail.log

コマンドで確認したエラーログの一部です。

Jan 13 15:20:12 PC名 postfix/smtp[56278]: connect to example.com[93.184.216.34]:25: Operation timed out Jan 13 15:20:12 PC名 postfix/smtp[56278]: 01BD81D21DB: to=<example@example.com>, relay=none, delay=85987, delays=85934/0.17/53/0, dsn=4.4.1, status=deferred (connect to example.com[93.184.216.34]:25: Operation timed out) Jan 13 15:20:19 PC名 postfix/master[56270]: master exit time has arrived Jan 13 15:21:12 PC名 postfix/smtp[56275]: connect to gmail-smtp-in.l.google.com[64.233.187.26]:25: Operation timed out ↑の同文4行 Jan 13 15:21:42 PC名 postfix/smtp[56275]: connect to alt1.gmail-smtp-in.l.google.com[74.125.25.26]:25: Operation timed out ↑の同文4行 Jan 13 15:22:12 PC名 postfix/smtp[56275]: connect to alt2.gmail-smtp-in.l.google.com[64.233.168.26]:25: Operation timed out ↑の同文4行 Jan 13 15:22:42 PC名 postfix/smtp[56275]: connect to alt3.gmail-smtp-in.l.google.com[173.194.75.27]:25: Operation timed out ↑の同文4行 Jan 13 15:23:12 PC名 postfix/smtp[56275]: connect to alt4.gmail-smtp-in.l.google.com[173.194.204.27]:25: Operation timed out Jan 13 15:23:12 PC名 postfix/smtp[56275]: warning: 0FB301ACB3C: defer service failure Jan 13 15:23:12 PC名 postfix/smtp[56280]: warning: 119E81BEBC7: defer service failure Jan 13 15:23:12 PC名 postfix/smtp[56282]: connect to alt4.gmail-smtp-in.l.google.com[173.194.204.27]:25: Operation timed out Jan 13 15:23:12 PC名 postfix/smtp[56282]: warning: 131511D1D18: defer service failure Jan 13 15:23:12 PC名 postfix/smtp[56282]: 131511D1D18: to=<Gmaiアカウントのユーザー名@gmail.com>, relay=none, delay=87523, delays=87290/0.19/233/0, dsn=4.4.1, status=deferred (connect to alt4.gmail-smtp-in.l.google.com[173.194.204.27]:25: Operation timed out) Jan 13 15:23:12 PC名 postfix/smtp[56284]: connect to alt4.gmail-smtp-in.l.google.com[173.194.204.27]:25: Operation timed out Jan 13 15:23:12 PC名 postfix/smtp[56284]: warning: 1F7B51D1CF9: defer service failure Jan 13 15:23:12 PC名 postfix/smtp[56284]: 1F7B51D1CF9: to=<Gmaiアカウントのユーザー名@gmail.com>, relay=none, delay=87557, delays=87324/0.22/233/0, dsn=4.4.1, status=deferred (connect to alt4.gmail-smtp-in.l.google.com[173.194.204.27]:25: Operation timed out) Jan 13 15:23:12 PC名 postfix/smtp[56286]: connect to alt4.gmail-smtp-in.l.google.com[173.194.204.27]:25: Operation timed out Jan 13 15:23:12 PC名 postfix/smtp[56286]: warning: 236DB1BC365: defer service failure

一応、Gmailアカウント側で安全性の低いアプリへのアクセスを有効にもしましたが、効果はありませんでした。

エラーログでエラーログでポートが25のままなのが気になったので/etc/postfix/main.cf の下段を

# Minimum Postfix-specific configurations. #mydomain_fallback = localhost mail_owner = _postfix setgid_group = _postdrop relayhost=[smtp.gmail.com]:587 # Enable SASL authentication in the Postfix SMTP client. smtp_sasl_auth_enable=yes smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd smtp_sasl_security_options= noanonymous smtp_sasl_mechanism_filter = plain # Enable Transport Layer Security (TLS), i.e. SSL. smtp_use_tls=yes smtp_tls_security_level=encrypt tls_random_source=dev:/dev/urandom

と修正しましたが解消されず、エラーログは

Jan 13 16:36:06 PC名 postfix/postfix-script[57768]: refreshing the Postfix mail system Jan 13 16:36:06 PC名 postfix/master[53653]: reload -- version 2.11.0, configuration /etc/postfix Jan 13 16:36:13 PC名 postfix/master[57779]: daemon started -- version 2.11.0, configuration /Library/Server/Mail/Config/postfix Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 0FB301ACB3C: from=<_www@ドメイン.com>, size=1073, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 01BD81D21DB: from=<ユーザー名@ドメイン.com>, size=348, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 119E81BEBC7: from=<_www@ドメイン.com>, size=947, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 131511D1D18: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 1F7B51D1CF9: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 236DB1BC365: from=<_www@ドメイン.com>, size=1098, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 28EF61D1C2B: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 3424C1DF15C: from=<ユーザー名@ドメイン.com>, size=330, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 4EB811D2BF8: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 5B1551D23E9: from=<_www@ドメイン.com>, size=947, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 5FD811BE974: from=<_www@ドメイン.com>, size=834, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 6E8921BC324: from=<_www@ドメイン.com>, size=1098, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 6F7D11D1F6C: from=<ユーザー名@ドメイン.com>, size=331, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 721431E066A: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 7BC201E09B9: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 8411A1DF9DF: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 8A63D1BC2BD: from=<_www@ドメイン.com>, size=1098, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 950B41DEDBE: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 9BA9C1D2266: from=<ユーザー名@ドメイン.com>, size=351, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 9DC981D2C41: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: 9DF491BEE5F: from=<_www@ドメイン.com>, size=822, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: A40971D1A70: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: BC38A1DDB28: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: C45201BEA56: from=<_www@ドメイン.com>, size=832, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: CDD0D1D2268: from=<ユーザー名@ドメイン.com>, size=351, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: DCF8D1DFB65: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: E01FE1BC250: from=<_www@ドメイン.com>, size=1060, nrcpt=1 (queue active) Jan 13 16:36:13 PC名 postfix/qmgr[57781]: E08341BCBCD: from=<_www@ドメイン.com>, size=1052, nrcpt=1 (queue active) Jan 13 16:36:14 PC名 postfix/pickup[57780]: 5BEA11E1CD6: uid=501 from=<ユーザー名> Jan 13 16:36:14 ドメイン postfix/cleanup[57782]: 5BEA11E1CD6: message-id=<20160113073614.5BEA11E1CD6@ドメイン.com> Jan 13 16:36:14 PC名 postfix/qmgr[57781]: 5BEA11E1CD6: from=<ユーザー名@ドメイン.com>, size=359, nrcpt=1 (queue active) Jan 13 16:37:06 PC名 postfix/smtp[57787]: connect to example.com[93.184.216.34]:25: Operation timed out Jan 13 16:37:06 PC名 postfix/smtp[57787]: 01BD81D21DB: to=<example@example.com>, relay=none, delay=90601, delays=90548/0.23/53/0, dsn=4.4.1, status=deferred (connect to example.com[93.184.216.34]:25: Operation timed out) Jan 13 16:37:13 PC名 postfix/master[57779]: master exit time has arrived

となりました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2016/01/13 07:59

Postfixの設定や動作確認がどこまで進んでいるか、下記ページを参考にしてみて示してくだされば、回答が得やすいと思います。 Postfixによるメールサーバーの構築 http://linux.kororo.jp/cont/server/postfix.php
guest

回答2

0

ベストアンサー

投稿2016/01/13 08:41

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sug1t0m0

2016/01/20 11:42

ありがとうございます。教えていただいた方法でメールが送れたのでBAにしたいと思います。
guest

0

メールサーバーのDNSは引けているから、ファイアウォールなどでSMTP関連ポートが塞がれている可能性を調査してみてはいかがでしょうか。

OS X:アプリケーションファイアウォールについて - Apple サポート
https://support.apple.com/ja-jp/HT201642

もうひとつ、「Outbound Port 25 Blocking」の線も点検を。

MacOSXでサーバー稼業 : Postfixの追加設定-SubmissionPortによるOP25B対応-
http://earlybirds.ddo.jp/namahage/inegalog/article.php?id=41

投稿2016/01/13 08:30

編集2016/01/13 08:34
退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sug1t0m0

2016/01/13 09:17

ご指摘ありがとうございます。 まず、ファイヤーウォールは使用していませんでした。 「Outbound Port 25 Blocking」の線なのですが、私の使用しているプロバイダがOCNで、調べてみたら下記のようなページがありました。 http://service.ocn.ne.jp/mail/info/op25b/ ご紹介いただいた下記のURLの http://earlybirds.ddo.jp/namahage/inegalog/article.php?id=41 通りに設定しようと考えているのですが、OSのバージョンの違いのせいか/etc/postfix/master.cfの修正箇所がなく submission inet n - n - - smtpd -o smtpd_tls_security_level=encrypt と最初からコメントアウトが外され、行も短い状態でした。 telnet localhost 587 コマンドの結果は PC名:PHP ユーザー名$ telnet localhost 587 Trying ::1... Connected to localhost. Escape character is '^]'. 220 ホスト名 ESMTP Postfix EHLO localhost 250-ホスト名 250-PIPELINING 250-SIZE 10485760 250-VRFY 250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN quit 221 2.0.0 Bye Connection closed by foreign host. となったので問題はないと考えています。これを使ってGmailアカウントからメールを送信するにはどのような方法があるのでしょうか。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問