首页 文章

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

提问于
浏览
8

我已经尝试在StackOverflow和其他网站上发布了每个单独的脚本/代码/方法,但没有运气 . 我在GoDaddy上主持 . 我已经设置了一个Google App帐户,设置了MX Records所需的一切(使用GoDaddy工具),甚至尝试从我的网站的GMAIL界面发送一些电子邮件,以及通过我的一个unix上的终端中的SMTP发送电子邮件机器 . 一切都奏效了 .

但是,当我尝试使用PHP时,却没有!难道GoDaddy会以某种方式阻止它吗?

我总是收到:

SMTP - >错误:无法连接到服务器:连接被拒绝(111)SMTP错误:无法连接到SMTP主机 . 邮件程序错误:SMTP错误:无法连接到SMTP主机 .

这是我用于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>

谢谢!

11 回答

  • 22

    不幸的是,你甚至无法使用像GoDaddy这样的DYNDNS这样的出站邮件服务,它们只允许你使用他们的中继服务器 . 限制 .

  • 2

    您可以使用您的Gmail,让Godaddy在Cpanel中启用远程邮件交换器 . 您必须要求他们这样做,因为您无法在cpanel中访问它

  • 0

    以下是一些信息:http://aravindisonline.blogspot.in/2012/01/phpmailer-with-godaddy-smtp-email.html

    这对我有用:

    $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;
    
  • 7

    我不支持Godaddy,因为他们一般很糟糕,但这对我有用 . 他们可能已经更新了系统 .

    $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; 
        }
    }
    

    哦,我也想要每个人,我不关心OOP!

  • 0

    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();
    
  • 3

    我遇到了同样的问题,经过不同的网站后,我找到了这个问题并且 it actually worked!

    GoDaddy does allow 使用Gmail作为您的SMTP发送电子邮件,只需要摆脱smtp.gmail.com并使用他们的主机代替 . 这是我的设置:

    $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...
    

    参考(见前两篇)http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

  • 1

    使用localhost作为托管goDaddy服务器上的主机 . 使用以下端口25,465,587 . GoDaddy的设置:

    答案与此链接有关:PHPMailer GoDaddy Server SMTP Connection Refused由@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;
    

    不需要SMTP Auth.It工作完美!

  • 0

    我终于修复了这个对 //$mail->isSMTP(); 线的评论 . 之后,我的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;
    
  • 1

    如前所述,GoDaddy has been known to block outgoing SSL SMTP connections赞成强制您使用自己的外发邮件服务器 .

    对于GoDaddy作为公司,注册商和网络主机的巨大自负,这几乎是冰山一角 . Ditch'em .

  • 1

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

  • 0

    更简单 . 奇怪的是你需要注释行“// $ mail-> IsSMTP();” . 是的,确定,它的SMTP,但是如果启用此行,则无法发送邮件 . ...不需要更多配置 . 只有这个评论行 .

相关问题