Click here to Skip to main content
15,742,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need assistance with smtp when i run the below code using localhost (xampp) it send emails but when I run in on the docker image it give me this error message:

SMTP NOTICE: EOF caught while checking if connected 2022-01-27 09:18:14 SMTP Error: Could not connect to SMTP host. 2022-01-27 09:18:14 SMTP connect() failed.

This is the code:
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->Host = "";
$mail->Port = 587;
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->CharSet = "UTF-8";
$mail->Username = "emailaddress";
$mail->Password = "password";

$email = "to:email adress";

$mail->Fromname = "Docker";


$mail->Subject = 'Test email Docker';
$message = '

<title>Test email



if (!$mail->send()) {

echo "Mail failed***********";
} else {

echo "mail sent!!!!!!!!!!!!";

What I have tried:

I tried adding the below on my docker file but still got the error message.

RUN apt-get install -q -y ssmtp mailutils

RUN echo "root=emailaddress" >> /etc/ssmtp/ssmtp.conf

# Here is the gmail configuration (or change it to your private smtp server)
RUN echo "" >> /etc/ssmtp/ssmtp.conf
RUN echo "AuthUser=emailaddress" >> /etc/ssmtp/ssmtp.conf
RUN echo "AuthPass=password" >> /etc/ssmtp/ssmtp.conf

RUN echo "UseTLS=YES" >> /etc/ssmtp/ssmtp.conf
RUN echo "UseSTARTTLS=YES" >> /etc/ssmtp/ssmtp.conf

# Set up php sendmail config
RUN echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900