身份验证失败[SMTP:STARTTLS失败(代码:220,响应:2.0.0准备启动TLS)] [英] authentication failure [SMTP: STARTTLS failed (code: 220, response: 2.0.0 Ready to start TLS)]

查看:952
本文介绍了身份验证失败[SMTP:STARTTLS失败(代码:220,响应:2.0.0准备启动TLS)]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am trying to send email with attachment in PHP using SMTP and PEAR but getting the error as "authentication failure [SMTP: STARTTLS failed (code: 220, response: 2.0.0 Ready to start TLS)]"

<?php
require_once "Mail.php"; // PEAR Mail package
require_once ('Mail/mime.php'); // PEAR Mail_Mime packge

$from = "Your Mom <sender@gmail.com>";
$to = "Me <recepient address@gmail.com>";
$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?<br /><br />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("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
}
?>`

PHP版本:1.10.1
PEAR版本:7.1.6

此处
请帮助我清除错误...

PHP version:1.10.1 PEAR version:7.1.6
got the code from here please help me to clear the error...

推荐答案

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

Here example code how to send tls/ssl emails with php to gmail smtp servers https://github.com/breakermind/PhpMimeParser/blob/master/PhpSmtpSslSocketClient.php It very simple with php stream sockets (**You need allow in mail.com panel send email from external apps **)

这篇关于身份验证失败[SMTP:STARTTLS失败(代码:220,响应:2.0.0准备启动TLS)]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆