LoginSignup
3
8

More than 5 years have passed since last update.

さくらVPSでPHPプログラムからメールを送信できるようにする

Posted at

メール送信は、postfixを使います。

Postfixをインストール

yum -y install postfix

Postfixの設定を更新

vi /etc/postfix/main.cf

ドメイン関連

#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = {ドメイン}
#mydomain = domain.tld
mydomain = {ドメイン}

インタフェース関連

inet_interfaces = all ← 行頭 # 削除
#inet_interfaces = localhost ← 行頭 # 追記

IPv6に未対応対策

# Enable IPv4, and IPv6 if supported
#inet_protocols = all
inet_protocols = ipv4

スプール

# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
home_mailbox = Maildir/ ← 行頭 # 削除

SMTP認証の設定

メール送信用サーバーとして利用可能にするため、以下を最後に追記。

smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unauth_destination

Postfixを起動

service postfix start
chkconfig postfix on

Submissionポート設定

Postfixの設定を開く。

vi /etc/postfix/master.cf

下記内容に更新。

# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
#       (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp   inet n   -   n   -   -   smtpd
submission inet n   -   n   -   -   smtpd ← 行頭 # 削除
# -o smtpd_enforce_tls=yes
 -o smtpd_sasl_auth_enable=yes ← 行頭 # 削除
 -o smtpd_client_restrictions=permit_sasl_authenticated,reject ← 行頭 # 削除

Postfixを再起動

service postfix reload
3
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
8