Dockerfile
COPY php.ini /usr/local/etc/php/conf.d/
RUN apt-get update &&\
apt-get install --no-install-recommends --assume-yes --quiet ca-certificates curl git &&\
rm -rf /var/lib/apt/lists/*
RUN curl -Lsf 'https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz' | tar -C '/usr/local' -xvzf -
ENV PATH /usr/local/go/bin:$PATH
RUN go get github.com/mailhog/mhsendmail
RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail
RUN echo 'sendmail_path = /usr/bin/mhsendmail --smtp-addr mailhog:1025' > /usr/local/etc/php/php.ini
docker-compose.yml
version: '3'
services:
GKapp:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: GKapp
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: GKapp
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
mailhog:
image: mailhog/mailhog:v1.0.0
ports:
- "1025:1025"
- "8025:8025"
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
我正在尝试的东西如下:-
docker exec -it GKapp bash
cat /usr/local/etc/php/php.ini
sendmail_path = /usr/bin/mhsendmail --smtp-addr mailhog:1025
/usr/bin/mhsendmail --help
Usage of /usr/bin/mhsendmail:
-f, --from string SMTP sender (default "www@2693eda79e6e")
-i, --long-i Ignored. This flag exists for sendmail compatibility. (default true)
-o, --long-o Ignored. This flag exists for sendmail compatibility. (default true)
-t, --long-t Ignored. This flag exists for sendmail compatibility. (default true)
--smtp-addr string SMTP server address (default "localhost:1025")
-v, --verbose Verbose mode (sends debug output to stderr)
/usr/bin/mhsendmail [email protected] <<EOF
From: Andy <[email protected]>
To: Test <[email protected]>
Subject: Hello, Andy!
Hey there,
Missing you pig time.
Hogs & Kisses,
Andy
EOF
error sending mail
2022/08/31 12:52:42 dial tcp 127.0.0.1:1025: getsockopt: connection refused
因此,我无法使用 mailhog 从容器内以及本地文件系统上的脚本发送电子邮件:-
电子邮件.php
<?php
$to = "[email protected]";
$subject = "Hey, I’m Pi Hog Pi!";
$body = "Hello, MailHog!";
$headers = "From: [email protected]" . "\r\n";
mail($to, $subject, $body, $headers);
echo 'email sent';
以上方法都不管用吗?帮助。
我也遇到同样的问题。 通过这种方式安装即可解决问题:
RUN curl -LkSso /usr/bin/mhsendmail 'https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64'&&
chmod 0755 /usr/bin/mhsendmail &&
echo 'sendmail_path = "/usr/bin/mhsendmail --smtp-addr=mailhog:1025"' > /usr/local/etc/php/php.ini;