2016-05-31 75 views
-1

有什麼我失蹤?我搜索了很高和低,我不確定我的代碼有什麼問題。也是我使用公共而不是郵件?SMTP有gmail錯誤。我沒有收到郵件

<?php 
require_once('phpmailer.php'); 
class Mail extends PhpMailer 
{ 
    // Set default variables for all new objects 
    public $mail  = IsSMTP; 
    public $From  = '[email protected]'; 
    public $FromName = SITETITLE; 
    public $Host  = 'smtp.gmail.com'; 
    public $port  = 587; 
    public $Mailer = 'smtp'; 
    public $SMTPAuth = true; 
    public $Username = '[email protected]'; 
    public $Password = 'password'; 
    public $SMTPSecure = 'tls'; 
    public $WordWrap = 75; 

    public function subject($subject) 
    { 
     $this->Subject = $subject; 
    } 

    public function body($body) 
    { 
     $this->Body = $body; 
    } 

    public function send() 
    { 
     $this->AltBody = strip_tags(stripslashes($this->Body))."\n\n"; 
     $this->AltBody = str_replace("&nbsp;", "\n\n", $this->AltBody); 
     return parent::send(); 
    } 
} 

這是我當前的代碼,並且問題尚未解決。任何新想法?

+0

我曾經嘗試都587和465 – Jayy

+0

可能重複的[PHPMailer的SMTP錯誤:無法連接到服務器](http://stackoverflow.com/questions/36351817/phpmailer-smtp-error-failed-to-connect-to-server) – brimstone

+0

你不能只使用Gmail郵件服務器來垃圾郵件。 – user2260040

回答

0

最有可能的一個端口。

public $port  = '4587'; 

if you tried configuring your SMTP server on port 465 (with SSL/TLS) and port 587 (with STARTTLS), but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL/TLS).

Apple Mail users: At times, Mail may misinterpret your SMTP server settings. If you currently have 'smtp.gmail.com:[email protected]' in the 'Outgoing Mail Server:' field of your settings, please try changing the field to 'smtp.gmail.com' and saving your settings.

https://support.google.com/mail/answer/78775?hl=en

你混合465個587端口。

如果它仍然不起作用,您可以嘗試調試連接。例如,請參閱PHPMailer only sends email when SMTPDebug = true

此外,從文檔:

/** 
* SMTP class debug output mode. 
* Debug output level. 
* Options: 
* * `0` No output 
* * `1` Commands 
* * `2` Data and commands 
* * `3` As 2 plus connection status 
* * `4` Low-level data output 
* @var integer 
* @see SMTP::$do_debug 
*/ 
public $SMTPDebug = 0; 

使用它,找出問題可能是什麼。它會告訴你它停在哪裏。

+0

固定,但仍然沒有 – Jayy

+0

檢查調試 - 更新的answear – Grzegorz

0

端口應,而不是4587.

以下是Gmail默認SMTP設置;

  • 的Gmail SMTP服務器地址:smtp.gmail.com
  • 的Gmail SMTP賬號:您 完整的Gmail地址(例如[email protected]
  • Gmail的SMTP密碼:你的Gmail密碼
  • 的Gmail SMTP端口(TLS):587
  • Gmail的SMTP端口(SSL):465
  • Gmail的SMTP TLS/SSL要求:是

,並請你用下面的改線

public $mail = 'IsSMTP()' 

+0

您建議將gmail憑證發送到smtp.mandrillapp.com? – zerkms

+0

@zerkms我誤解了主機。 –

+0

已編輯,但未收到正面結果 – Jayy

0

更改端口固定一個SMTP:465

相關問題