SMTP Connect() failed

Hi

sending mail has been acting strange recently. the sending mail functions that have been working fine now become " SMTP Connect() failed". My SMTP server are working fine as I managed to send from a plain text PHP script. Have tested with GMail, Yahoo SMTP also but got the same error " SMTP Connect() failed". Anything else I need to check on ?

Below are the setting I have tried on on my PHPMaker.

Yahoo:
SMTP server: smtp.mail.yahoo.com
SMTP server port : 465
SMTP server user name: myyahoo@yahoo.com
SMTP server password: myYahoomailPassword
Security : SSL

Gmail
SMTP server: smtp.gmail.com
SMTP server port : 465 (also tried 587 with TLS)
SMTP server user name: myyahoo@gmail.com
SMTP server password: myGmailPassword
Security : SSL

Company SMTP server:
SMTP server: smtp.xxx.com
SMTP server port : 25
SMTP server user name: blank
SMTP server password: blank
Security : blank


Thanks and regards
Ble

You may check your firewall settings of your server (that is your PC if you test it locally) hosting your site.

Make sure the “Security” in lower case, for example “tls” or “ssl”. It should work, as I have been trying it with “tls” and port 587.

Thanks

will try those security and lower case.

the testmail script is workign fine on both prodiction server and local computer. not sure if anything to deal with the PHPMaker setup bu twill trythe above and share the result.

bern_a3168 wrote:

the testmail script is workign fine on both prodiction server and local computer

Does your test email script use PHPMailer? If not, it is different, “SMTP Connect() failed” is a PHPMailer error message, read:
https://github.com/PHPMailer/PHPMailer/issues/270

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
setting phpmailer
“PHPMAILER_MAILER” => “smtp”, // PHPMailer mailer
“SMTP_SERVER” => “smtp.gmail.com”, // SMTP server
“SMTP_SERVER_PORT” => 465, // SMTP server port
“SMTP_SECURE_OPTION” => “ssl”,
“SMTP_SERVER_USERNAME” => “myemail@gmail.com”, // SMTP server user name
“SMTP_SERVER_PASSWORD” => “mypassw”, // SMTP server password
“SENDER_EMAIL” => “myemail”, // Sender email address
“RECIPIENT_EMAIL” => “”, // Recipient email address

yes, I was able to send email by using PHPMailer script. dont know why it’s not workign on my PHPMaker2020.

bern_a3168 wrote:

yes, I was able to send email by using PHPMailer script.

Can you post your code in that PHPMailer script?

arbei wrote:

bern_a3168 wrote:

yes, I was able to send email by using PHPMailer script.

Can you post your code in that PHPMailer script?

Below is my “sendmail.php” which I run on the same server and working fine.


<?php $servername = "localhost"; $username = "username"; $password = "adminpassword"; $dbname = "seahr"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed ***: " . $conn->connect_error); } require("PHPMailer_5.2.0/class.phpmailer.php"); $sql = "SELECT temp_seq, temp_requester, temp_name, requester_fullname, requester_email, end_date, case_name, reminder_sent FROM temp_staff"; $result = $conn->query($sql); $today = date("Y-m-d"); $tday = strtotime(date("Y-m-d")); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $date_diff=0; $sent_update=0; $current_end_date = strtotime($row["end_date"]); //echo "
today date :".$today." / "."Name: ".$row["requester_fullname"]." / ".$row["end_date"]." / ".$row["reminder_sent"]; if (($today <= $row["end_date"]) and ($row["reminder_sent"] < 4)) { $date_diff = ceil($current_end_date - $tday) /86400; echo "
Date diff =".$date_diff; if ($date_diff ==7){$sent_update=1;} elseif ($date_diff ==3) {$sent_update=2;} elseif ($date_diff ==0) {$sent_update=3;} echo "
sent_update =".$sent_update; if (($sent_update = 1) or ($send_update =2) or ($sent_update=3)) { $sql2 = "update temp_staff set reminder_sent=".$sent_update." where temp_seq =".$row['temp_seq']; if ($conn->query($sql2) === TRUE) { echo "
Contract:".$row["requester_fullname"]." updated successfully"; } else { echo "Error updating record: " . $conn->error; } //echo "
- ** Tem Seq:".$row["temp_seq"]." - id: " . $row["temp_requester"]. " - Email: " . $row["requester_email"]. " - Diff date: " .$date_diff."
"; echo "
Set sent update = ".$sent_update; SendMsg($row["temp_seq"],$row["requester_fullname"],$row["requester_email"],$row["case_name"],$row["temp_name"],$row["end_date"],$date_diff,$sent_update); } } \ \ } } else { echo "0 results"; } $conn->close(); \ \ \ /**************************************/ /* Send mail */ /**************************************/ function SendMsg($seq,$req_fullname,$req_email,$case_name,$temp_name,$end_date,$diff,$seq_alert) { echo "
arg1= ".$seq; echo "
arg2= ".$req_fullname; echo "
arg3= ".$req_email; echo "
arg4= ".$case_name; echo "
arg5= ".$temp_name; echo "
arg6= ".$end_date; echo "
arg7= ".$diff; echo "
arg7= ".$seq_alert; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; \ \ $mail = new PHPMailer(); // set mailer to use SMTP $mail->IsSMTP(); \ \ $mail->Host = "smtpbgk.xxx.com"; // specify main and backup server $mail->Port = 25; $mail->SMTPAuth = true; // turn on SMTP authentication // When sending email using PHPMailer, you need to send from a valid email address // In this case, we setup a test email account with the following credentials: // email: // pass: password $mail->Username = ""; // SMTP username $mail->Password = "letmein"; // SMTP password \ \ //$mail->From = ""; //$mail->FromName = "SEA Temp Staff Request"; //$mail->AddAddress($req_email); //$mail->AddCC(""); //$mail->AddBCC(""); $mail->From = ""; $mail->AddAddress(""); $mail->FromName = "SEA Temp Staff Request-test"; $mail->AddCC(""); $mail->AddBCC(""); \ \ // set word wrap to 50 characters $mail->WordWrap = 50; // set email format to HTML $mail->IsHTML(true); $mail->Subject = "Alert ".$seq_allert."-CTA account will be expired on ".$end_date; $mail->Body = "\n". "Hello ".$req_fullname; $mail->Body .= "

". "This email serves as a reminder that below CTA's contract will be expiring soon."; $mail->Body .= "

". "Case name: ".$case_name; $mail->Body .= "
". "CTA name: ".$temp_name; $mail->Body .= "
". "Expiring date: ".$end_date; $mail->Body .= "
"."If not, kindly ensure the CTA comes to the office and do exit clearance (submission of exit form, returning of laptop and bandges) with local BSE, on the last working day."; $mail->Body .= "

"; $mail->Body .= "
". "Best regards"; if(!$mail->Send()) { echo "
Message could not be sent.."; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "
Message has been sent -----------
"; \ \ } \ \ ?>



------------------------- end of script --------------------------------------------

Even a basic mail sending from the built-in function on PHPMaker2020 still not able to make it work. I still got my PHPMaker v12 running on Windows 7 and still working as expected with the same settings below.

SMTP server : smtpbgk.xxx.com
SMTP server port : 25
SMTP user name:
SMTP server password :
sender email: myemail@my.com
recipient email: recipient@mail.com


don’t know what went wrong.

  1. bern_a3168 wrote:

require(“PHPMailer_5.2.0/class.phpmailer.php”);

PHPMaker v2020 uses PHPMailer ~6.0.7, if you want to test if it is due to PHPMailer issue (which I don’t think so), you can change “phpmailer/phpmailer”: “~6.0.7” to “phpmailer/phpmailer”: “5.2.0” in the generated composer.json and run composer update again.

  1. bern_a3168 wrote:

SMTP server : smtpbgk.xxx.com
SMTP server port : 25
SMTP user name:
SMTP server password :

Are you sure your STMP server allow sending email without authentication?

Your script does use:

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = “watcharapan@xxx.com”; // SMTP username
$mail->Password = “letmein”; // SMTP password

“Are you sure your STMP server allow sending email without authentication?”
yes, if user access this portal within our organization network. outside network will require to access via VPN.

today I have setup another laptop with low security and setup with PHPmaker2020 version. setup mail, create a simple project that only mail to alert when adding, editing. uploaded to our production server to try out. the result is still remain the same with “SMTP connect() failed” “//github …”. the project that’s created by PHPmaker12 is running fine with the same server.

anything can try ?

thanks

  1. bern_a3168 wrote:

“Are you sure your STMP server allow sending email without authentication?”
yes, if user access this portal within our organization network. outside network will require to access via VPN.

I meant if your server requires username and password to authenticate before sending email. In your testing script you did use username and password but in the settings your post you did not use. If authentication is required, double check PHP Settings → Email tab, make sure you have enter username and password.

  1. Click Tools → Advanced Settings, make sure the setting “PHPMailer mailer” is set to “smtp”. I don’t remember any differences between old and new version except for this setting.

  2. I believe v12 used PHPMailer 5.2, your testing script also uses PHPMailer 5.2, so you may try PHPMailer 5.2 as suggested above, arbei wrote:

bern_a3168 wrote:

require(“PHPMailer_5.2.0/class.phpmailer.php”);

PHPMaker v2020 uses PHPMailer ~6.0.7, if you want to test if it is due to PHPMailer version issue, you can change “phpmailer/phpmailer”: “~6.0.7” to “phpmailer/phpmailer”: “5.2.0” in the generated composer.json and run composer update
again.

  1. Make sure you use PHP >= 5.6 as required by PHPMaker. (PHPMailer v5.2 requires PHP >= 5.0, but v6 requires PHP >= 5.5. If you try to use PHP < 5.5, it may not work.)

Thanks

finally managed to get mail notification after adding and editing data.

For Gmail:

  • have to do with the security setting from my account by changing to “Less secure”. so, sending with Gmail is no concern now. the test mail script also working with the current PHPMailer version.

For the company mail with port 25:

  • still not able to send out from the the PHPmaker setting (even tried with user name and password). the test mail script also not working with the current PHPMailer version (see error below).

Error: Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

It must be something wrong with the port or others from my server. Honestly the project from PHPMaker v12 is working fine with the same settings.

----- here is my test mail script -----------

<?php use PHPMailer\PHPMailer\PHPMailer; require 'vendor/autoload.php'; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = "smtpxxx.xxx.com"; $mail->Port = 25; $mail->SMTPAuth = true; $mail->Username = ''; $mail->Password = 'myADPassword'; $mail->setFrom(''); $mail->addAddress(''); $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the body.'; $mail->send(); \ \ if (!$mail->send()) { echo '
Mailer Error: '. $mail->ErrorInfo; } else { echo "
email sent......"; } ?>

anyway, thanks again for all your help on this post!

Regards

@bern, try this:
Edit your phpfn.php script and locate the following lines in function SendEmail:

if ($smtpSecure != “”) {
$mail->SMTPSecure = $smtpSecure;
$mail->SMTPOptions = [“ssl” => [“verify_peer” => FALSE, “verify_peer_name” => FALSE, “allow_self_signed” => TRUE]];
}

Change to this:

if ($smtpSecure != “”) {
$mail->SMTPSecure = $smtpSecure;
}
$mail->SMTPOptions = [“ssl” => [“verify_peer” => FALSE, “verify_peer_name” => FALSE, “allow_self_signed” => TRUE]];

I’ve had problems in the past sending email via port 25, so I have been using this change for a long time (at least since v2018). Give it a try.

ppinto wrote:

@bern, try this:
Edit your phpfn.php script and locate the following lines in function SendEmail:

if ($smtpSecure != “”) {
$mail->SMTPSecure = $smtpSecure;
$mail->SMTPOptions = [“ssl” => [“verify_peer”
=> FALSE, “verify_peer_name” => FALSE, “allow_self_signed”
=> TRUE]];
}

Change to this:

if ($smtpSecure != “”) {
$mail->SMTPSecure = $smtpSecure;
}
$mail->SMTPOptions = [“ssl” => [“verify_peer” =>
FALSE, “verify_peer_name” => FALSE, “allow_self_signed” =>
TRUE]];

I’ve had problems in the past sending email via port 25, so I have been using this
change for a long time (at least since v2018). Give it a try.


Hi PPinto

thanks a lot!
will find some times to try it out this week, will get back with the result. thanks again

@bern
If you use google mail. You must setting Control access to less secure apps
I use this setting to send email…

Thanks Nabilahasna

Managed to make it worked with Gmail. Still having issue with port 25 and company mail. So, I wrote a send mail script and call out from the app and pass values via url. Will keep it this way until can get a permanent fix.

Regards

myby try with email outlook.com