2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPのmail関数mb_send_mail関数でAWSからメールを配信(メルマガ作成用)

2
Posted at

AWSからPHPを使ってメール配信します。

まず、一番シンプルにmail関数で

$headers = ‘From: ‘. ‘sender@hoge.com’ . “\r\n” .
‘Reply-To: ‘.sender@hoge.com’ . “\r\n” .
‘Return-Path: ‘.sender@hoge.com’ . “\r\n” .
‘X-Mailer: PHP/’ . phpversion(); //改行してOK
mail(‘receiver@hoge.com’, ‘タイトル’ , ‘本文’ , $headers, ‘-f’. ‘sender@hoge.com’);

第五引数が、スパム振り分けを喰らわないための大事なものその①。
gmailやhotmailなんかでは普通に表示されているが、昔の話を聞くと日本語が化けることがあるよう。
これを解決するには…

マルチバイト対応のmb_send_mail関数を利用する

mb_language(“japanese”);
mb_internal_encoding(“UTF-8”);
mb_send_mail(‘receiver@hoge.com’, ‘タイトル’ , ‘本文’ , $headers, ‘-f’. ‘sender@hoge.com’);

しかし送ったメールのヘッダ見ると、JISになっているから意味ないんじゃ…謎が残る。メールは殆どJISですよ、という10年くらい前の記事がいっぱい出てくるので現状が分からん。書物してると大抵utf8だけど、メールは違うのだろうか。

Content-Type: text/plain; charset=ISO-2022-JP

サーバー側の設定

スパム振り分けを喰らわないための大事なものその②。ip4: の後ろは設置するサーバーのip。

TXT
VALUE: "v=spf1 ip4:00.00.00.000 -all"```

設定がちゃんとされてるかは、```nslookup -type=TXT xxxx.com``` とコマンドを打つことでも確認できる。
```Non-authoritative answer:
xxx.com text = “v=spf1 ip4:52.68.61.205 -all”```
みたいに返ってくる。
```dig xxx.com txt``` というコマンドでも見れる。
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?