簡體   English   中英

如果用戶名帶點,則使用PHP的Gmail SMTP電子郵件無法發送

[英]Gmail SMTP EMail using PHP not sending if username has dot

我正在嘗試使用gmail SMTP發送html電子郵件,當我使用自己的帳戶時,效果很好。

但是,如果我的用戶名帶有(。)點,則不會發送電子郵件,它以錯誤結尾,提示“無法將郵件發送到myemail@domain.com,錯誤:534-5.7.14”;

下面是我的代碼:

require("smtp.php");

/* Uncomment when using SASL authentication mechanisms */

require("sasl/sasl.php");


$from="me@mydomain.com";                           /* Change this to your address like "me@mydomain.com"; */ $sender_line=__LINE__;
$to="to@otherdomain.com";                             /* Change this to your test recipient address */ $recipient_line=__LINE__;

if(strlen($from)==0)
    die("Please set the messages sender address in line ".$sender_line." of the script ".basename(__FILE__)."\n");
if(strlen($to)==0)
    die("Please set the messages recipient address in line ".$recipient_line." of the script ".basename(__FILE__)."\n");

$smtp=new smtp_class;

$smtp->host_name="smtp.gmail.com";       /* Change this variable to the address of the SMTP server to relay, like "smtp.myisp.com" */
$smtp->host_port=587;                /* Change this variable to the port of the SMTP server to use, like 465 */
$smtp->ssl=0;                       /* Change this variable if the SMTP server requires an secure connection using SSL */

$smtp->http_proxy_host_name='';     /* Change this variable if you need to connect to SMTP server via an HTTP proxy */
$smtp->http_proxy_host_port=3128;   /* Change this variable if you need to connect to SMTP server via an HTTP proxy */

$smtp->socks_host_name = '';        /* Change this variable if you need to connect to SMTP server via an SOCKS server */
$smtp->socks_host_port = 1080;      /* Change this variable if you need to connect to SMTP server via an SOCKS server */
$smtp->socks_version = '5';         /* Change this variable if you need to connect to SMTP server via an SOCKS server */

$smtp->start_tls=1;                 /* Change this variable if the SMTP server requires security by starting TLS during the connection */
$smtp->localhost="localhost";       /* Your computer address */
$smtp->direct_delivery=0;           /* Set to 1 to deliver directly to the recepient SMTP server */
$smtp->timeout=10;                  /* Set to the number of seconds wait for a successful connection to the SMTP server */
$smtp->data_timeout=0;              /* Set to the number seconds wait for sending or retrieving data from the SMTP server.
                                       Set to 0 to use the same defined in the timeout variable */
$smtp->debug=1;                     /* Set to 1 to output the communication with the SMTP server */
$smtp->html_debug=1;                /* Set to 1 to format the debug output as HTML */
$smtp->pop3_auth_host="";           /* Set to the POP3 authentication host if your SMTP server requires prior POP3 authentication */
$smtp->user="use.rname";                     /* Set to the user name if the server requires authetication */
$smtp->realm="gmail.com";                    /* Set to the authetication realm, usually the authentication user e-mail domain */
$smtp->password="******";                 /* Set to the authetication password */
$smtp->workstation="";              /* Workstation name for NTLM authentication */
$smtp->authentication_mechanism=""; /* Specify a SASL authentication method like LOGIN, PLAIN, CRAM-MD5, NTLM, etc..
                                       Leave it empty to make the class negotiate if necessary */

/*
 * If you need to use the direct delivery mode and this is running under
 * Windows or any other platform that does not have enabled the MX
 * resolution function GetMXRR() , you need to include code that emulates
 * that function so the class knows which SMTP server it should connect
 * to deliver the message directly to the recipient SMTP server.
 */
if($smtp->direct_delivery)
{
    if(!function_exists("GetMXRR"))
    {
        /*
        * If possible specify in this array the address of at least on local
        * DNS that may be queried from your network.
        */
        $_NAMESERVERS=array();
        include("getmxrr.php");
    }
    /*
    * If GetMXRR function is available but it is not functional, to use
    * the direct delivery mode, you may use a replacement function.
    */
    /*
    else
    {
        $_NAMESERVERS=array();
        if(count($_NAMESERVERS)==0)
            Unset($_NAMESERVERS);
        include("rrcompat.php");
        $smtp->getmxrr="_getmxrr";
    }
    */
}

if($smtp->SendMessage(
    $from,
    array(
        $to
    ),
    array(
        "MIME-Version:1.0",
        "Content-Type:text/html; charset=ISO-8859-1",
        "From: $from",
        "To: $to",
        "Subject: Testing Email",
        "Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
    ),
    "<html><body>
<table width=100% border=0 cellspacing=0 cellpadding=5 style='font-family:Arial; font-size:14px;'>
<tr>
<td align=left width=30%><strong>First Name :</strong></td>
<td align=left>".ucwords($name)."</td>
</tr>
<tr>
<td align=left><strong>Last Name :</strong></td>
<td>".$lastname."</td>
</tr>
<tr>
<td align=left><strong>Company Name :</strong></td>
<td align=left>".$contactcompany."</td>
</tr>
<tr>
<td align=left><strong>Address :</strong></td>
<td align=left>".$contactaddress."</td>
</tr>
<tr>
<td align=left><strong>Country :</strong></td>
<td align=left>".$contactcountry."</td>
</tr>
<tr>
<td align=left><strong>Postal / Zip Code :</strong></td>
<td align=left>".$contactpostal."</td>
</tr>
<tr>
<td align=left><strong>Tel :</strong></td>
<td align=left>".$contacttel."</td>
</tr>
<tr>
<td align=left><strong>Mobile :</strong></td>
<td align=left>".$contactmobile."</td>
</tr>
<tr>
<td align=left><strong>Email :</strong></td>
<td align=left>".$email."</td>
</tr>
<tr>
<td align=left><strong>How did you know us? </strong></td>
<td align=left>".$contactknowus."</td>
</tr>
<tr>
<td align=left>Others</td>
<td align=left>".$contactspecify."</td>
</tr>
<tr>
<td align=left><strong>Status :</strong></td>
<td align=left>".$contactstatus."</td>
</tr>
<tr>
<td align=left><strong>Message :</strong></td>
<td valign=top align=left>".$message."</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>


</table></body></html>"))
        echo "Message sent to $to OK.\n";
        else
            echo "Could not send the message to $to.\nError: ".$smtp->error."\n";
      ?>

提前致謝。

沒有理由避免使用點來發送用戶名的電子郵件,這是胡說八道。

錯誤534-5.7.14表示Password command failed 可能的解決方案是通過您的帳戶登錄Google,該方法無效,然后使用此鏈接:

https://accounts.google.com/b/0/DisplayUnlockCaptcha

之后,單擊Continue按鈕以完成對其他設備/應用程序的電子郵件的激活。

然后再嘗試通過此腳本發送消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM