这里有没有使用PHPMailer类的机构? [英] Has any body here used PHPMailer class?
本文介绍了这里有没有使用PHPMailer类的机构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图运行这段代码,这实际上是PHPMailer编写者编写的一个例子。我在修改后的版本中使用了我的实际电子邮件地址。
这是代码:
<?php
/ * *
*此示例显示通过Google的Gmail服务器发送时使用的设置。
* /
// SMTP需要准确的时间,并且必须设置PHP时区
// 这应该在你的php.ini中完成,但如果您无法访问该
date_default_timezone_set( ETC / UTC'跨度>);
需要' ../ PHPMailer / PHPMailerAutoload.php';
// 创建新的PHPMailer实例
$ mail = 新 PHPMailer;
// 告诉PHPMailer使用SMTP
$ mail- > isSMTP();
// 启用SMTP调试
// 0 =关闭(供生产使用)
// 1 =客户端消息
// 2 =客户端和服务器消息
$ mail-> SMTPDebug = 2 ;
// 请求HTML友好的调试输出
$ mail-> Debugoutput = ' html';
// 设置邮件服务器的主机名
$ mail-> Host = ' smtp.gmail.com';
// 使用
/ / $ mail-> Host = gethostbyname('smtp.gmail.com');
// 如果您的网络不支持SMTP over IPv6
// 设置SMTP端口号 - 587用于经过身份验证的TLS,即RFC4409 SMTP提交
$ mail-> Port = 587 跨度>;
// 设置加密系统使用 - ssl(不建议使用)或tls
$ mail-> SMTPSecure = ' tls';
// 是否使用SMTP身份验证
$ mail- > SMTPAuth = true;
// 用于SMTP身份验证的用户名 - 使用gmail的完整电子邮件地址
$ mail->用户名= MyUsername@gmail.com;
// 用于SMTP身份验证的密码
$ mail - >密码= MyPassword;
// 设置邮件的发送方式
$ mail-> setFrom(' MyUsername@yahoo.com',' 名字姓氏');
// 设置备用回复地址
$ mail-> addReplyTo(' MyUsername@yahoo.com',' 名字姓氏');
// 设置邮件发送给谁
$ mail-> addAddress(' MyUsername@gmail.com',' 名字姓氏');
// 设置主题行
$ mail-> ; Subject = ' PHPMailer GMail SMTP test';
// 从外部文件读取HTML邮件正文,将引用的图像转换为嵌入式图像
// 将HTML转换为基本的纯文本替代正文
$ mail-> msgHTML(file_get_contents(' contents.html'),dirname(__ FILE__) );
// 将纯文本正文替换为手动创建的纯文本正文
$ mail-> AltBody = ' 这是一个纯文本邮件正文;
// 附加图片文件
$ mail-> ; addAttachment(' images / phpmailer_mini.png');
// 发送消息,检查错误
< span class =code-keyword> if (!$ mail-> send()){
echo 邮件程序错误:。 $ MAIL-> ERRORINFO;
} 其他 {
echo 发送消息!;
}
?>
I收到以下错误消息:
SERVER - >客户: 220 smtp.gmail.com ESMTP kb5sm59150446wjc。 20 - gsmtp
客户 - >服务器:EHLO localhost
SERVER - >客户:250-smtp.gmail.com为您服务,[ 105 。 112 。 26 。 194 ] 250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
客户端 - >服务器:STARTTLS
SERVER - >客户: 220 2 。 0 。< span class =code-digit> 0 准备启动TLS
客户端 - >服务器:EHLO localhost
SERVER - >客户:250-smtp.gmail.com为您服务,[ 105 。 112 。 26 。 194 ] 250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
客户 - >服务器:AUTH LOGIN
SERVER - >客户: 334 VXNlcm5hbWU6
客户 - >服务器:Y3BsdXNwcm9nQGdtYWlsLmNvbQ ==
SERVER - >客户: 334 UGFzc3dvcmQ6
客户 - >服务器:Z3JlYXRlcndvcmtzY29uY2VwdHNvcm8 =
SERVER - >客户:534-5。 7 。 14 < https: // 跨度> <跨度类= 代码注释> accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbudm534-5.7.14 7dRJ9nF9vOvnbQyIqnWIzkoFdffSjNsJB_kyKe-gxiKa06mVdZFiXeMVQDKyojoOrjs8so534-5.7.14 8a0uEyzWF1_Ndjv3Vub5_4IIr6njn6YoBlD32FnjbQO8bu3V6cyoIL7nhiFhktM4_EW3pg534-5.7 .14 ErczQyvIUDEbjUUOkYEktvxAbbnCJ9Wd8kJW_3xLYCj9mfHi1T3tjC_bM6OVv-YZfP6CEE534-5.7.14 e_aH7GtdrLmQbnYK5Rpw_MvM7Wes>请通过您的网络浏览器和534-5.7.14登录,然后重试.534-5.7.14了解更多信息,请点击534 5.7.14 https://support.google.com/mail/answer/78754 kb5sm59150446wjc.20 - gsmtp
SMTP错误:密码命令失败:534-5。 7 。 14 < https : // accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbudm534-5.7.14 7dRJ9nF9vOvnbQyIqnWIzkoFdffSjNsJB_kyKe-gxiKa06mVdZFiXeMVQDKyojoOrjs8so534-5.7.14 8a0uEyzWF1_Ndjv3Vub5_4IIr6njn6YoBlD32FnjbQO8bu3V6cyoIL7nhiFhktM4_EW3pg534-5.7.14 ErczQyvIUDEbjUUOkYEktvxAbbnCJ9Wd8kJW_3xLYCj9mfHi1T3tjC_bM6OVv-YZfP6CEE534-5.7.14 e_aH7GtdrLmQbnYK5Rpw_MvM7Wes>请通过您的网络浏览器和534-5.7.14登录,然后重试.534-5.7.14了解更多信息,请点击534 5.7.14 https://support.google.com/mail/answer/78754 kb5sm59150446wjc.20 - gsmtp
SMTP错误:无法进行身份验证。
客户 - >服务器:退出
服务器 - >客户: 221 2 。 0 。< span class =code-digit> 0 关闭连接kb5sm59150446wjc。 20 - gsmtp
SMTP connect()失败。 https: // github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
邮件程序错误: SMTP connect()失败。 https: // github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
另外,我在非google恢复邮箱中收到谷歌发来的电子邮件,某人试图签名-in我的邮件由一个不符合现代安全标准的应用程序。
那么我错了什么?
解决方案
mail = 新 PHPMailer;
// 告诉PHPMailer使用SMTP
MAIL-> isSMTP();
// 启用SMTP调试
// 0 =关闭(供生产使用)
// 1 =客户端消息
// 2 =客户端和服务器消息
mail-> SMTPDebug = 2 ;
// 请求HTML友好的调试输出
I attempted running this code which is actually an example written by the writers of PHPMailer.I used my actual email addresses in my modified version.
Here is the code:
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "MyUsername@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "MyPassword";
//Set who the message is to be sent from
$mail->setFrom('MyUsername@yahoo.com', 'Firstname Lastname');
//Set an alternative reply-to address
$mail->addReplyTo('MyUsername@yahoo.com', 'Firstname Lastname');
//Set who the message is to be sent to
$mail->addAddress('MyUsername@gmail.com', 'Firstname Lastname');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I got the following error message:
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP kb5sm59150446wjc.20 - gsmtp
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [105.112.26.194]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [105.112.26.194]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: Y3BsdXNwcm9nQGdtYWlsLmNvbQ==
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: Z3JlYXRlcndvcmtzY29uY2VwdHNvcm8=
SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbudm534-5.7.14 7dRJ9nF9vOvnbQyIqnWIzkoFdffSjNsJB_kyKe-gxiKa06mVdZFiXeMVQDKyojoOrjs8so534-5.7.14 8a0uEyzWF1_Ndjv3Vub5_4IIr6njn6YoBlD32FnjbQO8bu3V6cyoIL7nhiFhktM4_EW3pg534-5.7.14 ErczQyvIUDEbjUUOkYEktvxAbbnCJ9Wd8kJW_3xLYCj9mfHi1T3tjC_bM6OVv-YZfP6CEE534-5.7.14 e_aH7GtdrLmQbnYK5Rpw_MvM7Wes> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 kb5sm59150446wjc.20 - gsmtp
SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbudm534-5.7.14 7dRJ9nF9vOvnbQyIqnWIzkoFdffSjNsJB_kyKe-gxiKa06mVdZFiXeMVQDKyojoOrjs8so534-5.7.14 8a0uEyzWF1_Ndjv3Vub5_4IIr6njn6YoBlD32FnjbQO8bu3V6cyoIL7nhiFhktM4_EW3pg534-5.7.14 ErczQyvIUDEbjUUOkYEktvxAbbnCJ9Wd8kJW_3xLYCj9mfHi1T3tjC_bM6OVv-YZfP6CEE534-5.7.14 e_aH7GtdrLmQbnYK5Rpw_MvM7Wes> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 kb5sm59150446wjc.20 - gsmtp
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection kb5sm59150446wjc.20 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Also, I recived an email from google in my non-google recovery mail box that an attempt was made to by someone to sign-in to my mail by an app that doesn't meet modern security standards.
So what am I getting wrong?
解决方案
mail = new PHPMailer; //Tell PHPMailer to use SMTP
mail->isSMTP(); //Enable SMTP debugging // 0 = off (for production use) // 1 = client messages // 2 = client and server messages
mail->SMTPDebug = 2; //Ask for HTML-friendly debug output
这篇关于这里有没有使用PHPMailer类的机构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文