実現したいこと
Docker + Nginx + PHPで実際にメールを送信したい
mailhogだと実際にメールが送信されないので、どのように実装すればいいかわかっていません
発生している問題・エラーメッセージ
gmailやicloudにメールが送信されない。
php
1if(mb_send_mail("test@gmail.com", "test_sub", "test_body", "test_header")){ 2 echo "成功"; 3} else { 4 echo "失敗"; 5}
「成功」が出力されるのですが、メール受信ができません
ご教示いただけますと幸いです
ファイル構成
/test └ docker-compose.yml ├ nginx │ ├ Dockerfile │ ├ default.conf │ └ nginx.conf └ app ├ index.php ├ Dockerfile ├ php.ini ├ sendmail.ini └ update-exim4.conf
該当のソースコード
docker
1version: "3" 2services: 3 nginx: 4 build: 5 context: ./nginx 6 ports: 7 - 8080:8080 8 volumes: 9 - ./app:/usr/share/nginx/html 10 11 php: 12 image: php:7-fpm 13 build: 14 context: ./app 15 ports: 16 - 25:25 17 volumes: 18 - ./app:/usr/share/nginx/html 19
app/Dockerfile
1FROM php:7-fpm 2COPY php.ini /usr/local/etc/php/php.ini 3COPY sendmail.ini /usr/local/etc/php/conf.d/ 4COPY update-exim4.conf /etc/exim4/update-exim4.conf.conf 5RUN apt-get -y update && apt-get install -y msmtp mailutils
app/index.php
1<?php 2 mb_language("Japanese"); 3 mb_internal_encoding("UTF-8"); 4 5 $to = 'xxxxxx@example.com'; 6 $subject = "テスト"; 7 $body = "これはテストです。\n"; 8 $from = "xxxxxx@example.com"; 9 $header = "From: $from\nReply-To: $from\n"; 10 11 mb_send_mail($to, $subject, $body, $header); 12?>
app/php.ini
1[Date] 2date.timezone = "Asia/Tokyo" 3 4[mbstring] 5mbstring.language = Japanese 6mbstring.internal_encoding = UTF-8
app/sendmail.ini
1sendmail_path = /usr/sbin/sendmail -t
app/update
1dc_eximconfig_configtype='internet' 2dc_other_hostnames='' 3dc_local_interfaces='127.0.0.1;::1' 4dc_readhost='exim4' 5dc_relay_domains='' 6dc_minimaldns='true' 7dc_relay_nets='' 8dc_smarthost='' 9CFILEMODE='644' 10dc_use_split_config='true' 11dc_hide_mailname='true' 12dc_mailname_in_oh='true' 13dc_localdelivery='mail_spool'
nginx/default.conf
1server { 2 listen 8080; 3 listen [::]:8080; 4 server_name localhost; 5 6 root /usr/share/nginx/html; 7 index index.html index.htm index.php; 8 9 location / { 10 try_files $uri $uri/ /index.php$is_args$args; 11 } 12 13 error_page 500 502 503 504 /50x.html; 14 location = /50x.html { 15 root /usr/share/nginx/html; 16 } 17 18 location ~ \.php$ { 19 root /usr/share/nginx/html; 20 fastcgi_pass php:9000; 21 fastcgi_index index.php; 22 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 23 include fastcgi_params; 24 } 25 26} 27
nginx/Dockerfile
1FROM nginx:latest 2 3COPY default.conf /etc/nginx/conf.d 4COPY nginx.conf /etc/nginx/nginx.conf
nginx/nginx.conf
1user nginx; 2worker_processes auto; 3 4error_log /var/log/nginx/error.log notice; 5pid /var/run/nginx.pid; 6 7events { 8 worker_connections 1024; 9} 10 11http { 12 include /etc/nginx/mime.types; 13 default_type application/octet-stream; 14 15 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 16 '$status $body_bytes_sent "$http_referer" ' 17 '"$http_user_agent" "$http_x_forwarded_for"'; 18 19 access_log /var/log/nginx/access.log main; 20 sendfile on; 21 keepalive_timeout 65; 22 include /etc/nginx/conf.d/*.conf; 23} 24
参考
https://blog.myntinc.com/2020/01/docker-composer-php-fpmsendmail.html
https://www.techgaku.com/run-nginx-with-php-in-docker-container/

あなたの回答
tips
プレビュー