- Macbook M1
- php:8.1.29-cli
- maihog/mailhog:latest
- PHPMailer >
Код: Выделить всё
// run.php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->Username = null;
$mail->Password = null;
$mail->Port = 1025;
//Recipients
$mail->setFrom('[email protected]', 'Test Sender');
$mail->addAddress('[email protected]', 'Test Receiver');
//Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body in bold![/b]';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
- Я запустил Mailhog в контейнере с портом 1025 smtp, 8025 web.
li>
Мне удалось отправить электронное письмо, и mailhog перехватил это письмо.
У меня есть файл компоновки Docker.
Я сомневаюсь, что все эти порты заблокированы, поэтому я изменил 1025, 8081, 51200... например. Ни один из них не работает.
Код: Выделить всё
version: "1.0"
name: worker
services:
mailhog:
container_name: "mail_server"
image: mailhog/mailhog
ports:
- 8025:8025
- 1025:1025
networks:
- internet
cronjob:
container_name: "workers"
build:
context: .
dockerfile: Dockerfile
networks:
- internet
- proxy-net
volumes:
- ./src/logs:/var/www/app/logs
# command: tail -f /dev/null # Keep container running
command:
- php
- index.php
networks:
internet:
driver: bridge
Код: Выделить всё
ARG WORKDIR=/var/www/app
FROM php:8.1.29-cli
#FROM php:8.1.29-apache
#FROM webdevops/php-apache:8.1
ARG ENV
ARG WORKDIR
RUN apt update && apt install -y libicu-dev && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install mysqli pdo_mysql
RUN docker-php-ext-enable mysqli pdo_mysql
RUN docker-php-ext-configure intl && docker-php-ext-install intl
WORKDIR $WORKDIR
COPY ./src ./
COPY ./vendor ./vendor
Код: Выделить всё
workers | 2024-06-28 04:44:45 SMTP ERROR: Failed to connect to server: Cannot assign requested address (99)
workers | 2024-06-28 04:44:45 SMTP Error: Could not connect to SMTP host. Failed to connect to server
workers | Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host. Failed to connect to serverSMTP server error: Failed to connect to server SMTP code: 99 Additional SMTP info: Cannot assign requested address
Подробнее здесь: https://stackoverflow.com/questions/786 ... to-mailhog