9

I have tried EVERY single script/code/method posted on StackOverflow and other sites for this, but with no luck. I am hosting on GoDaddy. I have setup a Google App account, set up everything needed for MX Records (using the GoDaddy tool for that), and even tried sending some emails from the GMAIL interface for my site, as well as through SMTP in terminal on one of my unix machines. It all worked.

HOWEVER, when I try using PHP, it doesn't! Is it like GoDaddy blocking it somehow?

I always receive:

SMTP -> ERROR: Failed to connect to server: Connection refused (111) SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

Here's the code I am using for PHPMailer:

<html>
    <head>
        <title>PHPMailer - SMTP (Gmail) advanced test</title>
    </head>
    <body>
    <?php
    require_once('../class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

    $mail->IsSMTP(); // telling the class to use SMTP

    try {
        $mail->Host       = "smtp.gmail.com"; // SMTP server
        $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
        $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
        $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
        $mail->Username   = "MYFROMADDRESSHERE";  // GMAIL username
        $mail->Password   = "MYFROMPASSWORDHERE";            // GMAIL password
        $mail->AddReplyTo('MYFROMADDRESSHERE', 'Sender Name');
        $mail->AddAddress('TESTTOADDRESSHERE', 'Recipient Name');
        $mail->SetFrom('MYFROMADDRESSHERE', 'Sender Name');
        $mail->AddReplyTo('MYFROMADDRESSHERE', 'Sender Name');
        $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
        $mail->MsgHTML(file_get_contents('contents.html'));
        $mail->AddAttachment('images/phpmailer.gif');      // attachment
        $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
        $mail->Send();
        echo "Message Sent OK</p>\n";
    } catch (phpmailerException $e) {
        echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
        echo $e->getMessage(); //Boring error messages from anything else!
    }
    ?>
</html>

Thanks!

JoHa
  • 1,989
  • 10
  • 28
  • 42
  • Easy way to test, if you have shell access: Log into the server, and try "telnet smtp.gmail.com 465". You won't be able to do the SSL stuff, but if there's a firewall issue, you'll get "connection refused" there as well. If it connects then hangs for input, it's not a firewall and is something with your code. – Marc B Mar 26 '11 at 02:52
  • I don't have SHELL enabled on this server, and it takes 48 hours to activate it; need to solve this within a few hours. Any other suggestions? – JoHa Mar 26 '11 at 03:17

11 Answers11

25

As discussed previously, GoDaddy has been known to block outgoing SSL SMTP connections in favor of forcing you to use their own outgoing mail server.

This is pretty much the tip of the iceberg, with regard to the immense suckitude of GoDaddy as a company, registrar and web host. Ditch'em.

Community
  • 1
  • 1
Charles
  • 50,943
  • 13
  • 104
  • 142
  • Does it mean I either shift to another hosting or I am stuck?! GoDaddy's mail is very slow! Also, if GMAIL uses SSL and they block that, is there any other service that works? I don't care whether it is GMAIL or not, as long as it shows "@mydomain.com" from messages I send, AND as long as they DO NOT go to the JUNK of users (although I added SPF for my domain, the GoDaddy default mailer is still sending to my users junk) – JoHa Mar 26 '11 at 03:54
  • 1
    It means you should find a good, reputable host. There are other mail services out there, but I do not know of one that would be suitable for you. (I like Amazon SES, but there's a huge learning curve because you have to modify your code to send through it instead of using SMTP.) – Charles Mar 26 '11 at 03:59
  • 8
    Just confirmed this with GoDaddy's customer support; what a poor service. – JoHa Mar 26 '11 at 20:13
  • It is possible to do this. See my answer below. – ecairol Oct 15 '13 at 02:34
7

I had the same problem, and after going through different sites, I found this one and it actually worked!

GoDaddy does allow to send emails using Gmail as your SMTP, just need to get rid of the smtp.gmail.com and use their Host instead. This is my setup:

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "your-account@gmail.com";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...

Reference (see first two posts) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

ecairol
  • 6,233
  • 1
  • 27
  • 26
  • 7
    Using *their* SMTP server is by definition **not** using Gmail's SMTP server. Sending email as your Gmail address (or Google Apps address) may present a significant spam issue, as their servers are *not* going to be SPF or DKIM cleared for sending as your Gmail user account. – Charles Oct 15 '13 at 02:54
  • Thanks a bunch @ecairol, your answer help me work it out using swift mailer too. – Selvin Ortiz May 31 '14 at 07:28
  • 1
    Confirmed GoDaddy issue for me with WordPress. I used the WP-Mail-SMTP and set the following: "From Email","From Name","Send all wordpress emails via SMTP","Set the return-path to match the From E-mail","SMTP Host: relay-hosting.secureserver.net", "SMTP Port: 25", "No Encryption", "No SMTP Authentication" – Mike Averto Jun 05 '15 at 10:46
6

I finally fixed this putting a comment on the //$mail->isSMTP(); line. After that my Gmail account started working fine in Godaddy.

require 'PHPMailer/class.phpmailer.php';
require 'PHPMailer/PHPMailerAutoload.php';


$mail = new PHPMailer;


 $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $subject = 'Your subject';

    $body = "From: $name\n E-Mail: $email\n Comments:\n $message";


//$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxxxxxxx@gmail.com';
$mail->Password = 'xxxxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port =587;
serenesat
  • 4,611
  • 10
  • 37
  • 53
  • 3
    This is not a "fix"; It makes your gmail account "work" by not using your gmail account. – Synchro Jul 28 '16 at 20:58
  • Thanks, I've tried to get phpmailer working for a few days now. I'm not sure how this fixes it, but it works. – nomaam Sep 22 '16 at 04:25
  • 1
    I struggled with this problem today on a GoDaddy Linux server, getting "Failed to connect to server: Connection refused (111)" using PHPMailer 5.6. This simple change worked after trying several other suggestions. I have G Suite handling the mail for my domain, and I don't use GoDaddy email, so I need to use smtp.gmail.com to send. I don't understand why it works, but this is still a current answer for this situation in February 2019. – BobSnider Feb 10 '19 at 04:29
  • Just my thoughts... when enabling $mail->isSMTP(), PHPMailer attempts to use the mailer built into my local server. Commenting it out uses the $mail->Host that I specify in my script. This immediately fixed my issue. I can't thank you enough. – Terry Carter Jan 04 '23 at 18:56
2

Use localhost as the host on your hosting goDaddy server. Using the following ports 25,465,587. Settings for GoDaddy:

Answer relates to this link:PHPMailer GoDaddy Server SMTP Connection Refused by @Nate Bryam

 $this->mail->Host = 'localhost';  
    //$this->mail->SMTPAuth = true;                               
    //$this->mail->Username = 'xxx@gmail.com';            
    //$this->mail->Password = 'xxx';                      
    //$this->mail->SMTPSecure = 'ssl';                           
    //$this->mail->Port = 465;//25;//587; 

There is no need for SMTP Auth.It works perfect!

Community
  • 1
  • 1
Wang'l Pakhrin
  • 858
  • 3
  • 15
  • 29
  • it works only if you use GoDaddy mail settings in your MX records (eg. if you set GSuite MX records to use an external mail provider then it will silently fails); when it works, it is perfect as long as you don't care that all the mails sent will arrive into user's spam folder ;) – guari Mar 10 '17 at 13:32
  • This worked for me... I didn't need anything fancy - just send an email with the message and subject to the recipient specified in the "contact us" form, and lo and behold that's exactly what this allows me to do. I didn't set up any MX records (I assume they're defaulted). All I did was create an email account and set that as the FROM address while setting the replyTO as the user's entered email address. – Edge D-Vort Apr 24 '17 at 21:03
1

The only option they have is to use the domain and use their e-mail service to send mail.

george
  • 11
  • 1
1

require_once('PHPMailerAutoload.php');

                    $mail = new PHPMailer();
                    $mail->isSMTP();
                    $mail->Host = "relay-hosting.secureserver.net";
                    $mail->Username = 'chandana@gmail.com';
                    $mail->Password = 'fwxnorhqttkxydr';
                    $mail->SetFrom($email);
                    $mail->Subject = 'enquiry from YnRack site';
                    $mail->Body = 'enquiry from YnRack site' . $message . '"From: \"' . $name . $email;
                    $mail->IsHTML(true);
                    $mail->AddAddress('chandana@gmail.com');
                    $mail->Send();
chandana
  • 139
  • 8
1

Unfortunately you can't even use an outbound mail service like DYNDNS with GoDaddy, they only allow you to use their relay server. Limiting.

916 Networks
  • 545
  • 3
  • 10
  • 18
0

I'm not supporting Godaddy, because they generally sucks, but this working for me. They might have updated there systems.

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";

$mail->Port = 587; // or 587 or 465
$mail->IsHTML(true);
$mail->Username = "stuff@gmail.com";
$mail->Password = "password";
$mail->setFrom('gmail_account@gmail.com', 'Someone's name');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress("gmail_account@gmail.com");
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
        return false;
    } else {
        return true; 
    }
}

Oh I also want to everybody, I don't care about OOP!!!

Chad
  • 643
  • 2
  • 11
  • 22
0

you can use your gmail and have Godaddy enable Remote Mail Exchanger in Cpanel. You have to ask them do it because you do not have access to it in cpanel

user49100
  • 1
  • 1
  • 2
0

Here is some information: http://aravindisonline.blogspot.in/2012/01/phpmailer-with-godaddy-smtp-email.html

This works for me:

$mail->Host = "relay-hosting.secureserver.net";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->SMTPSecure = 'tsl';
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = false;
Benoît Latinier
  • 2,062
  • 2
  • 24
  • 36
0

Is more simple. strangely you need comment line "// $mail->IsSMTP();". Yes, ok, its SMTP, but if you enable this line, you can't send mail. ...don't need more configuration. Only this comment line.