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 <[email protected]>";
$to = "Me <recepient [email protected]>";
$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 = "[email protected]";
$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 version:1.10.1
PEAR version:7.1.6
got the code from here
please help me to clear the error...