質問編集履歴

3

関連するタグを追加しました

2019/06/13 02:56

投稿

apricot-works
apricot-works

スコア15

test CHANGED
File without changes
test CHANGED
File without changes

2

情報の追記

2019/06/13 02:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,103 @@
15
15
  サーバーの設定あるいはPHPの設定で何とかなる方法はないでしょうか。
16
16
 
17
17
  移行先のサーバーはさくらのレンタルサーバーです。
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ ※以下、追記内容となります。
26
+
27
+
28
+
29
+ あまり詳しくないので、上手く説明できないのですが・・・。
30
+
31
+ メールフォームの管理者宛てメールアドレスが「info@example.com」とします。
32
+
33
+ この「info@example.com」はGSuiteを使用しています。ビジネス用Gmailみたいなものです。
34
+
35
+ メールフォームのWEBサーバーはさくらのレンタルサーバーで、ドメインは「https://example.com」となります。
36
+
37
+ ドメインはお名前で管理しています。
38
+
39
+ mail関数(sendmail)で「info@example.com」に送信しようとすると、
40
+
41
+ メールアドレスがWEBサーバーと同一ドメインなのでGmailのほうではなく、
42
+
43
+ サーバー内部のメールアドレスへ送信しようとしてしまうらしく、Gmail側にメールが届きません。
44
+
45
+ さくらのレンタルサーバー側には「info」のメールアドレスは作成していません。
46
+
47
+ 下記URLと同じような状況です。
48
+
49
+ 参照:[同一ドメインで、Webとメールを別サーバで運用したときのメール送信問題](https://www.evoworx.co.jp/blog/domain-mail-problem/)
50
+
51
+
52
+
53
+ 上記のような理由により、sendmailではなくSMTP認証にて外部SMTPサーバーを使用してメールを送信したいのです。
54
+
55
+ 今回はその外部SMTPサーバーがGmailのSMTPサーバーとなっています。
56
+
57
+
58
+
59
+ ちなみにメール送信部分のコードは以下の通りです。
60
+
61
+ ```PHP
62
+
63
+ function sendmail($from, $to, $reply_to, $subject, $body, $mail_encode = 'UTF-8') {
64
+
65
+
66
+
67
+ $this->message = null;
68
+
69
+ $this->mail_encode = strtoupper($mail_encode);
70
+
71
+ $encode_from = $this->_encodeHeader('From', $from);
72
+
73
+ $encode_to = $this->_encodeHeader('To', $to);
74
+
75
+ $encode_reply_to = $this->_encodeHeader('Reply-to', $reply_to);
76
+
77
+ $encode_subject = $this->_encodeHeader('Subject', $subject);
78
+
79
+ $encode_body = $this->_encodeBody($body);
80
+
81
+ $matches = null;
82
+
83
+
84
+
85
+ if(preg_match('/<([0-9a-z\.\-_]+@[0-9a-z\.\-_]+)>$/i', $to, $matches)) $to = $matches[1];
86
+
87
+
88
+
89
+ $mail_header = array();
90
+
91
+ $mail_header[] = 'From: ' . $encode_from;
92
+
93
+ $mail_header[] = 'MIME-Version: 1.0';
94
+
95
+ $mail_header[] = 'Content-Type: text/plain; charset='. $this->mail_encode;
96
+
97
+ $mail_header[] = 'Content-Transfer-Encoding: ' . (strcmp('UTF-8', $this->mail_encode) == 0 ? 'base64' : '7bit');
98
+
99
+
100
+
101
+ if(strlen($encode_reply_to) > 0) $mail_header[] = 'Reply-To: ' . $encode_reply_to;
102
+
103
+
104
+
105
+ $send_mail = mail($to, $encode_subject, $encode_body, trim(join($this->eol, $mail_header)));
106
+
107
+
108
+
109
+ if($send_mail !== true) $this->message = $send_mail;
110
+
111
+
112
+
113
+ return $send_mail;
114
+
115
+ }
116
+
117
+ ```

1

2019/06/12 11:49

投稿

apricot-works
apricot-works

スコア15

test CHANGED
File without changes
test CHANGED
File without changes