Error! authentication failure - php

I am working on a php website,Using google smtp to send mail,The code is working fine and it is sending mail to inbox, Through google smtp.But now have changed the $username and $password,It is showing me this error,Thankyou in advance
Error! authentication failure [SMTP: Invalid response code received
from server (code: 534, response: 5.7.14 Please log in via your web
browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14
https://support.google.com/mail/answer/78754 y11-v6sm11496340pfn.92 - gsmtp)]
<?php
require_once 'Mail.php'; //this loads up PEAR Mail
if (!class_exists('Mail')) { die('Error: The PEAR Mail class does not exist.'); }
$host = 'ssl://smtp.gmail.com';
$username = '****#gmail.com'; //replace this with your new Gmail address
$password = '****'; //replace this with your new Gmail account password
$port = '465';
$from_email = $username;
$from = '"california worker company" <'.$from_email.'>'; //put your name in here, but keep the double quotes
$to = '"california worker company" <softphoton002#gmail.com>'; //put in your name and main email address to send a test to
$subject = 'California Worker Lead for GENERAL CONTRACTORS';
$myname = $_REQUEST['name'];
$myemail = $_REQUEST['email'];
$myphone = $_REQUEST['phone'];
$annualpayroll = $_REQUEST['annualpayroll'];
$numberofemployees = $_REQUEST['numberofemployees'];
$yourbusinesstype = $_REQUEST['yourbusinesstype'];
$healthinsurancecarrier = $_REQUEST['healthinsurancecarrier'];
$payrollservicemethod = $_REQUEST['payrollservicemethod'];
$body = 'Hello Admin <br/> You get a new lead for GENERAL CONTRACTORS.<br/>
Name:'.$myname.'<br/>
Email:'.$myemail.'<br/>
Phone:'.$myphone.'<br/>
Annual Payroll:'.$annualpayroll.'<br/>
Member of Employees:'.$numberofemployees.'<br/>
Business Type:'.$yourbusinesstype.'<br/>
Health Insurance Carrier:'.$healthinsurancecarrier.'<br/>
Payroll Service Method:'.$payrollservicemethod.'<br/>';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Reply-To' => $from_email,
'MIME-Version' => 1,
'Content-type' => 'text/html;UTF-8'
);
$params = array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
);
$smtp = Mail::factory('smtp', $params);
$mail = $smtp->send($to, $headers, $body);
// To user email
$headerss = array(
'From' => $from,
'To' => $myemail,
'Subject' => $subject,
'Reply-To' => $from_email,
'MIME-Version' => 1,
'Content-type' => 'text/html;UTF-8'
);
$paramss = array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
);
$smtps = Mail::factory('smtp', $paramss);
$bodys = 'Hello '.$myname.'<br/>
We received your message for Quote on GENERAL CONTRACTOR. We will reply you in next 24-48 hours.<br/>
Thank you';
$mails = $smtps->send($myemail, $headerss, $bodys);
if (PEAR::isError($mail)) {
echo '<p>Error! '.$mail->getMessage().'</p>';
} else {
header("Location: http://californiaworkercomp.com/general-contractors?success=1");
//echo '<p>Your test message was sent successfully.</p>';
}
?>

Related

Pear Php smtp relay server issue hosted iat GoDaddy

I have an HTML form for a website hosted on GoDaddy, I'm trying to allow users to use a contact form to contact me via my website, I've created an smtp PHP script however it doesn't seem to work, the script runs and the page reloads but I haven't received any income mail for this test.
<?php
include('Mail.php');
$host = 'localhost';
$username = '******#***********.com';
$password = '*******';
$subject = 'Test';
$from = '******#*********.com';
$to = '******.*******#***.com';
$cc = 'person to CC';
$recipients = $to . ", " . $cc; //
$headers = array ('From' => $from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => false,
'username' => $username,
'password' => $password,
'port' => '25'
));
$mail = $smtp->send($recipients, $headers, $body);
if ( PEAR::isError($mail) ) {
echo("<p>Error sending mail:<br/>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message sent.</p>");
}
header("Location:contact-us.html");
?>

SMTP Script for Google Mail

I have got the below script from this link. My Website is running with Digital Ocean hosting and I am unable to send a mail.
Can you please help me out to work. Also, How do I get to know
the actual mail failure ?
#!/usr/bin/php
<?php
if (PHP_SAPI !== 'cli') exit;
if (count($argv) < 4) {
echo 'Usage: ' . basename($_SERVER['PHP_SELF']) . ' <recipient1#recipient2#...> "<subject>" <"msg" or file>'."\n";
exit;
}
require_once "Mail.php";
$from = "xxx#gmail.com";
$aRecipients = (strpos($argv[1], '#')) ? explode('#', $argv[1]) : array($argv[1]);
$to = '';
foreach ($aRecipients as $recipient) $to .= "{$recipient},";
$to = rtrim($to, ',');
$subject = $argv[2];
$body = '';
if (file_exists($argv[3])) {
echo "[+] Delivering file {$argv[3]} to {$to}\n";
$body = file_get_contents($argv[3]);
} else {
$length = strlen($argv[3]);
echo "[+] Delivering text with length of {$length} to {$to}\n";
$body = "{$argv[3]}";
}
$host = gethostbyname('smtp.gmail.com');
$port = 465;
$username = "xxxx#gmail.com";
$password = "xxx";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp =& Mail::factory('smtp',
array(
'host' => $host,
'port' => $port,
'debug' => true, // set to true if u want to see what happens in the background
'auth' => true,
'username' => $username,
'password' => $password
)
);
$smtp->send($to, $headers, $body);
echo "[+] Mail sent :)\n";
?>
change your host smtp.gmail.com to ssl://smtp.gmail.com
try this
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'XXX#gmail.com',
'password' => 'xxx'
));
it might help you

PHP Pear Mail HTML Version

I'm able to send emails with text only, but none of the scripts are working to send HTML. I have authentication off, and google apps is authenticating based on the server IP
$message = 'Blah blah blah';
require_once "Mail.php";
$from = "mycompany <service#mycompany.com>";
$to = $fName.$lName." <".$email.">";
$subject = "Hello from mycompany!";
$body =
'Dear '.$fName.',
Thank you for your interest in mycompany. We have received your inquiry and will contact you within 24 hours.
Thanks,
Timothy Elliott - Owner/CEO mycompany';
$host = "tls://smtp-relay.gmail.com";
$port = "465";
$username = "";
$password = "";
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => false,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("There was an error, please try again.");
}
This code works just fine, but I'm not able to send it as an HTML message.
It's easy to do with with PEAR Mail - you just need to use PEAR Mail_Mime for encoding the HTML portion of your outgoing emails.
Here's an example of how.
Expanding your code for this, it should look something like:
<?php
require_once "Mail.php";
require_once "Mail/mime.php";
$from = "mycompany <service#mycompany.com>";
$to = $fName.$lName." <".$email.">";
$subject = "Hello from mycompany!";
$html = <<< HTML
<b>Dear $fName</b>,
<p>
Thank you for your interest in mycompany. We have received your inquiry and will contact you within 24 hours.
</p>
Thanks,<br/>
<i>Timothy Elliott - Owner/CEO mycompany</i>
HTML;
$host = "tls://smtp-relay.gmail.com";
$port = "465";
$username = "";
$password = "";
$headers = [
'From' => $from,
'To' => $to,
'Subject' => $subject
];
$crlf = "\n";
$mime = new Mail_mime(['eol' => $crlf]);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp',
[
'host' => $host,
'port' => $port,
'auth' => false,
'username' => $username,
'password' => $password
]
);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("There was an error, please try again.");
}

Sending mail via pear mail

Sorry for my English.
I’m trying to sent e-mai via Mail pear packet:
require_once "Mail.php";
$from = '<frommail#gmail.com>';
$to = '<tomail#vacant.lv>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'frommail#gmail.com',
'password' => 'pass'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
//email addresses are changed
But in result I have error:
Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Permission denied (code: -1, response: )]
Openssl is enabled.
Thanks you.
At some stage you might want to send an HTML email, so you would also need to use the Mail/mime package that is provided by PEAR. I've included that as well.
<?php
require_once "Mail.php";
require_once "Mail/mime.php";
$from = "<noreply#example.com>";
$to = "fred#example.com"; // the email address
$host = "smtp.gmail.com";
$port = "587";
// use the first example username if sending from gmail, as full email address
// is required
$username = "fred.flintstone#gmail.com";
$username = "fred";
$password = "secure";
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$mailbody = "<html><body>...</body></html>";
$mime = new Mail_mime();
$mime->setHTMLBody($mailbody);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory(
'smtp',array (
'host' => $host,
'auth' => true,
'username' => $username,
'password' => $password,
'port' => $port
)
);
// send email
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo "<b><Center>Succesfully sent email to</b>$to</center>";
}

Saving data to online text document

I have an issue which is i want to save the data to a online shared text document on google drive.
but it's not working.
There is No error , it's just not saving anything into the document and i've already gived the document the full access by public.
////// email code
require_once "Mail.php";
$from = "Babylovenappies <****#gmail.com>";
$to = "nassim#*****.com";
$recipients = $to;
$subject = $subject;
$body = $message;
$host = "ssl://smtp.googlemail.com";
$port = "465";
$username = "****#gmail.com";
$password = "****";
$headers = array ('From' => $from,
'To' => $to,
'Bcc' => "admin#***.com.au",
'Subject' => $subject,
'MIME-Version' => "1.0",
'Content-type' => "text/html; charset=iso-8859-1");
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($recipients, $headers, $body);
$fh = fopen('https://docs.google.com/document/d/1dS_MhqGnLkb22mwU6OKfxoiFcX0izRTvjjf8eJ7igiE/edit?usp=sharing', "a");
fwrite($fh, $to);
fclose($fh);
Thanks In Advance
You definitely should use API
Look at this:
Files: update

Categories