我正在尝试使用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> </td>
<td> </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";
?>
提前致谢。
答案 0 :(得分:0)
没有理由避免使用点发送用户名的电子邮件,这是无稽之谈。
错误534-5.7.14
表示Password command failed
。可能的解决方案是通过您的帐户登录Google,但无法使用此链接:
https://accounts.google.com/b/0/DisplayUnlockCaptcha
之后,单击Continue
按钮完成对其他设备/应用程序的电子邮件的激活。
然后再次尝试通过此脚本发送消息。