PHP on GoDaddy Linux Shared trying to send through

2020-01-27 07:59发布

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!

11条回答
来,给爷笑一个
2楼-- · 2020-01-27 08:10

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;
查看更多
再贱就再见
3楼-- · 2020-01-27 08:12

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.

查看更多
女痞
4楼-- · 2020-01-27 08:14

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!

查看更多
ゆ 、 Hurt°
5楼-- · 2020-01-27 08:16

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!!!

查看更多
Ridiculous、
6楼-- · 2020-01-27 08:25

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;
查看更多
我欲成王,谁敢阻挡
7楼-- · 2020-01-27 08:26

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

查看更多
登录 后发表回答