简体   繁体   English

GoDaddy Linux上的PHP共享尝试通过GMAIL SMTP发送

[英]PHP on GoDaddy Linux Shared trying to send through GMAIL SMTP

I have tried EVERY single script/code/method posted on StackOverflow and other sites for this, but with no luck. 我已经尝试过在StackOverflow和其他站点上发布的每个脚本/代码/方法,但是都没有运气。 I am hosting on GoDaddy. 我在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. 我已经设置了一个Google App帐户,设置了MX记录所需的所有内容(为此使用GoDaddy工具),甚至尝试通过GMAIL界面为我的网站发送一些电子邮件,以及在我的一个Unix终端上通过SMTP发送电子邮件机器。 It all worked. 一切正常。

HOWEVER, when I try using PHP, it doesn't! 但是,当我尝试使用PHP时,事实并非如此! Is it like GoDaddy blocking it somehow? 就像GoDaddy以某种方式阻止它吗?

I always receive: 我总是收到:

SMTP -> ERROR: Failed to connect to server: Connection refused (111) SMTP Error: Could not connect to SMTP host. SMTP->错误:无法连接到服务器:连接被拒绝(111)SMTP错误:无法连接到SMTP主机。 Mailer Error: SMTP Error: Could not connect to SMTP host. 邮件错误:SMTP错误:无法连接到SMTP主机。

Here's the code I am using for PHPMailer: 这是我用于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! 谢谢!

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. 如前所述, 已知GoDaddy会阻止传出SSL SMTP连接 ,从而迫使您使用他们自己的传出邮件服务器。

This is pretty much the tip of the iceberg, with regard to the immense suckitude of GoDaddy as a company, registrar and web host. 就GoDaddy作为公司,注册商和网络托管商的巨大吸引力而言,这几乎是冰山一角。 Ditch'em. Ditch'em。

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. GoDaddy 确实允许使用Gmail作为您的SMTP发送电子邮件,只需要摆脱smtp.gmail.com并使用其主机即可。 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/ 参考(请参阅前两篇文章) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

I finally fixed this putting a comment on the //$mail->isSMTP(); 我终于解决了这个问题,对//$mail->isSMTP();进行了注释//$mail->isSMTP(); line. 线。 After that my Gmail account started working fine in Godaddy. 之后,我的Gmail帐户开始在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;

Use localhost as the host on your hosting goDaddy server. 使用localhost作为托管goDaddy服务器上的主机。 Using the following ports 25,465,587. 使用以下端口25,465,587。 Settings for GoDaddy: GoDaddy的设置:

Answer relates to this link: PHPMailer GoDaddy Server SMTP Connection Refused by @Nate Bryam 答案与此链接有关:@Nate Bryam 拒绝PHPMailer GoDaddy Server SMTP连接

 $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! 不需要SMTP身份验证,它可以完美运行!

他们唯一的选择是使用域并使用其电子邮件服务发送邮件。

require_once('PHPMailerAutoload.php'); 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();

Unfortunately you can't even use an outbound mail service like DYNDNS with GoDaddy, they only allow you to use their relay server. 不幸的是,您甚至无法在GoDaddy上使用DYNDNS之类的出站邮件服务,它们仅允许您使用其中继服务器。 Limiting. 限制。

I'm not supporting Godaddy, because they generally sucks, but this working for me. 我不支持Godaddy,因为它们通常很烂,但这对我有用。 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!!! 哦,我也想要每个人,我不在乎OOP !!!

you can use your gmail and have Godaddy enable Remote Mail Exchanger in Cpanel. 您可以使用gmail并让Godaddy在Cpanel中启用Remote Mail Exchanger。 You have to ask them do it because you do not have access to it in cpanel 您必须要求他们这样做,因为您无法在cpanel中访问它

Here is some information: http://aravindisonline.blogspot.in/2012/01/phpmailer-with-godaddy-smtp-email.html 这是一些信息: 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;

Is more simple. 更简单。 strangely you need comment line "// $mail->IsSMTP();". 奇怪的是,您需要注释行“ // $ mail-> IsSMTP();”。 Yes, ok, its SMTP, but if you enable this line, you can't send mail. 是的,好的,它是SMTP,但是如果启用此行,则无法发送邮件。 ...don't need more configuration. ...不需要更多配置。 Only this comment line. 仅此注释行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM