Jump to content


Photo

[Solved] Cannot send email via Google/Outlook/Mailgun SMTP via PhpMailer

SMTP mail phpmailer google outlook

  • This topic is locked This topic is locked
4 replies to this topic

#1 zekus

zekus

    Newbie

  • Members
  • 3 posts

Posted 08 January 2018 - 07:46 PM

Hi Heliohost,

 

My username is Zekus.
I am using Tommy server.

 

I cannot send mail from Outlook/Gmail/Mailgun SMTP, which is working with my local WAMP.
 
This is the error I received.

 

2018-01-06 16:10:56 Connection: opening to smtp-mail.outlook.com:587, timeout=300, options=array()
2018-01-06 16:11:05 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp-mail.outlook.com:587 (Network is unreachable) [/home/zekus/public_html/*****/SMTP.php line 325]
2018-01-06 16:11:05 SMTP ERROR: Failed to connect to server: Network is unreachable (101)

 

 
But when I commented "$mail->isSMTP();" from my php file, it is working but an email will be sent to Junk mail.
I did try both port 465 for SSL and 587 for TLS.

Here is my PhpMailer code.

 

<?php
namespace PHPMailer;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

 
require_once 'PHPMailer.php';
require_once 'SMTP.php';
require_once 'Exception.php';
 
$mail = new PHPMailer;
$mail->IsSMTP();

$mail->SMTPDebug = 0;
$mail->Host = 'smtp-mail.outlook.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = True;

$mail->CharSet = 'UTF-8';  
$mail->SMTPKeepAlive = true;
 
$mail->Username = "admin@job4dent.com";
$mail->Password = "*****";
 
$mail->setFrom('admin@job4dent.com', 'Job4Dent');
$mail->addAddress('job4dent@outlook.com', 'John Doe');
 
$mail->Subject = 'PHPMailer 6.0 Outlook SMTP test';
$mail->Body =
            "Hi,<br>
            This system is working perfectly.";
$mail->IsHTML(true);
$mail->AltBody = 'This is a plain-text message body';

 
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

 

When I change Host to tommy.heliohost.org or change my username and password, my email can be sent

but with warning of fraud email that was not directly sent by Google/Outlook.

 

It can be tested via https://4dent.tk/cro...ClinicGMail.php

 

Many thanks,

Zekus


Edited by zekus, 08 January 2018 - 08:00 PM.


#2 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 13,946 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 08 January 2018 - 08:28 PM

Seeing it's 3 mail providers, I bet the ports are blocked in the firewall to prevent spam. Krydos would know for sure.

Escalating.

Please do not PM me for support. Posting on our forums lets all of us learn.
Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#3 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 22,423 posts
  • Gender:Male

Posted 09 January 2018 - 02:55 AM

# telnet smtp-mail.outlook.com 587
Trying 40.97.136.194...
Connected to smtp-mail.outlook.com.
Escape character is '^]'.
220 CY4PR15CA0002.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 9 Jan 2018 02:49:31 +0000
^]
telnet> quit
Connection closed.
Port 587 to outlook is open on Tommy.

#4 zekus

zekus

    Newbie

  • Members
  • 3 posts

Posted 09 January 2018 - 07:38 AM

Sorry, I forgot to mention that after I pointed my NS to HelioHost and it works, I changed it back to my registrar because I want to use their features.

 

Do I need to config MX or SPF from my registrar for mail sending to work?



#5 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 13,946 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 09 January 2018 - 12:24 PM

Things like SPF will probably be missing, which would explain the spam flags and blocks (the providers want to see a valid mail server when the look up the connecting party to reduce spam) . You can try creating the MX and related records manually (you'll need to go into cpanel and look in the MX editor and the DNS editor to see what the correct values are).

No guarantees it'll work though.

Please do not PM me for support. Posting on our forums lets all of us learn.
Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...






Also tagged with one or more of these keywords: SMTP, mail, phpmailer, google, outlook

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users