0

I am using PHPMailer with SMTP to send email. First I just test it from my localhost and it's successfully sent email.

But when I upload the same code to my service it's showing me following error without sending email;

Error Message is :

2016-04-22 05:53:10 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-22 05:53:10 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting mail is not send

I do not understand why it's showing me this error message becuase I am using 100% same code.

Here is my email sending script using PHPMailer :

require 'PHPMailerAutoload.php';
$m =  new PHPMailer();

$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;

$m->Host = 'smtp.gmail.com';
$m->Username = 'username';
$m->Password = 'password'; // google app password
$m->SMTPSecure =  'ssl';
$m->Port = 465;

$m->From = 'from@gmail.com';
$m->FromName = 'Shibbir Ahmed';
$m->addReplyTo('reply@gmail.com', 'Reply Address');
$m->addAddress('to@gmail.com', 'Shibbir Ahmed');

$m->Subject = 'Here is an email';
$m->Body = 'This is email';
$m->AltBody = 'Alt body';
if($m->send()) {
    echo 'mail send';
} else {
    echo 'mail is not send';
}
shibbir ahmed
  • 1,014
  • 2
  • 18
  • 34
  • 1
    Possible duplicate of [PHP on GoDaddy Linux Shared trying to send through GMAIL SMTP](http://stackoverflow.com/questions/5440026/php-on-godaddy-linux-shared-trying-to-send-through-gmail-smtp) – Synchro Apr 22 '16 at 07:42

2 Answers2

1

Some servers have certain functions disable that a user cannot enable them selves. Check with your hosting provider to see if they have the mail() function enabled.

In this case smtp mail function perfectly working in localhost but not in server.. soo you change the server setting

aarju mishra
  • 710
  • 3
  • 10
  • Thanks for your reply. I am using Godaddy Server. Can you tell where I have to go to fix it ? – shibbir ahmed Apr 22 '16 at 06:14
  • You can perform the following steps as my point of view. Log in to your GoDaddy account. Click Servers. Next to the account you want to use, click Manage. In the Account Summary area, next to SMTP Services your mail server name displays. – aarju mishra Apr 22 '16 at 06:19
  • I think user cannot set mail() function in server side – Yogesh Prajapati Apr 22 '16 at 06:25
  • I can't find the SMTP services link in my godaddy account – shibbir ahmed Apr 22 '16 at 06:26
  • You can do one thing just give comment to your username,password,port etc. $mail2->Host = localhost; //$mail2->SMTPAuth = false; //$mail2->Username = 'xxxx@xxxxxx.com'; //$mail2->Password = '*******'; //$mail2->SMTPSecure = 'tls'; //$mail2->Port = 465; I know this is silly but just check it by doing this. – aarju mishra Apr 22 '16 at 06:32
  • I know it will work without this info but I have to use SMTP service to send email within a few second and perfectly – shibbir ahmed Apr 22 '16 at 06:39
  • this is server side issue and you asked why this is not happening so I told you the reason.So please upvote the answer if you feel its useful to you in anyway.And ya you can check this link.I searched it on your behalf: https://github.com/Thoughtscript/wp-postlib_godaddy_php_emailer – aarju mishra Apr 22 '16 at 06:53
  • but what I exactly need to do ? – shibbir ahmed Apr 22 '16 at 07:01
0

That link to the troubleshooting guide is there for a reason - if you follow it it will tell you exactly what is wrong: GoDaddy blocks outbound SMTP, so you have to use their mail servers. There are many duplicates of this question, so search before you post.

Synchro
  • 35,538
  • 15
  • 81
  • 104