php加密tls失败,php – 身份验证失败[SMTP:STARTTLS失败(代码:220,响应:2.0.0准备启动TLS)]...

我正在尝试使用SMTP和PEAR在PHP中发送带附件的电子邮件,但将错误视为“身份验证失败[SMTP:STARTTLS失败(代码:220,响应:2.0.0准备启动TLS)]”

require_once "Mail.php"; // PEAR Mail package

require_once ('Mail/mime.php'); // PEAR Mail_Mime packge

$from = "Your Mom ";

$to = "Me ";

$subject = 'Call Me!';

$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);

// text and html versions of email.

$text = 'Hi son, what are you doing?nnHeres an picture of a cat for you.';

$html = 'Hi son, what are you doing?
Here is an picture of a cat

for you.';

// attachment

$file = 'fromc.xls';

$crlf = "n";

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);

$mime->setHTMLBody($html);

$mime->addAttachment($file, 'text/plain');

$body = $mime->get();

$headers = $mime->headers($headers);

$host = "smtp.gmail.com";

$username = "xyz@gmail.com";

$password = "xyz";

$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,

'username' => $username,'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {

echo("

" . $mail->getMessage() . "

");

}

else {

echo("

Message successfully sent!

");

}

?>`

PHP版本:1.10.1

PEAR版本:7.1.6

得到了here的代码

请帮我清除错误…

解决方法:

这里的示例代码如何使用php将tls / ssl电子邮件发送到gmail smtp服务器https://github.com/breakermind/PhpMimeParser/blob/master/PhpSmtpSslSocketClient.php使用php流套接字非常简单(**您需要在mail.com面板中允许从外部应用程序发送电子邮件**)

标签:php,email,smtp,pear

来源: https://codeday.me/bug/20191006/1859273.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值