-1

Having problem with sending mail from PHP script using google credentials.

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 r14sm3440046pfe.9 - gsmtp)]

// Pear Mail Library
require_once "Mail.php";

$from = '<somename@gmail.com>';
$to = '<anothername@gmail.com>';
$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' => 'somename@gmail.com',
        'password' => 'somepassword'
    ));

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

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}

With the stack answer i make a try, the answer link is: send-email-using-the-gmail-smtp-server-from-a-php-page

Ref: http://pear.php.net

Community
  • 1
  • 1
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42

1 Answers1

1

Sorry for being late. If login fails once on a device (in this case your server running the pear mail package). You must enable the device access using the display unlock captcha once . Even if you enable less secure apps access on your gmail account as stated in many answers. Once you do that I am sure you will be ready to go.Please note that this answer can be valid for a particular amount of time so marking such questions as duplicate or saying they have answers elsewhere is both unfair and discouraging. The answers provided may no longer be valid or just half correct.

Stephen Mudere
  • 444
  • 3
  • 10