An attempt was made to access a socket in a way forbidden by its access permissions. (10013). Send Email using PHP Mailer via new Gmail App password - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Saturday, September 3, 2022

An attempt was made to access a socket in a way forbidden by its access permissions. (10013). Send Email using PHP Mailer via new Gmail App password

Recently Google disabled the feature of allow off less secure apps for SMTP Authentication. I got to know that I have to use an App Password from my google account. I did all the instructed documentation from a blog, but I can't send an email using PHP mailer. I am not able to figure out the error.

The Code I have tried :

<?php
// Import PHPMailer classes at the top
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation
$mail = new PHPMailer(true);
// Server settings
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure= 'ssl';
$mail->Port = 465;
$mail->SMTPOptions = array(
    'ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
    )
);
$mail->Username = 'uqureshi269@gmail.com';
$mail->Password = 'akuocvvdclceirgi';
// Sender &amp; Recipient
$mail->From = 'uqureshi269@gmail.com';
$mail->FromName = 'SENDER NAME';
$mail->addAddress('dqureshiumar@gmail.com');
// Content
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Encoding = 'base64';
$mail->Subject = 'Subject';
$body = 'This is a test message';
$mail->Body = $body;
if($mail->send()){
  echo 'Success Message';
  exit;
}else{
  echo 'Error Message';
  exit;
}
?>

Below is the error I am facing:

2022-09-02 19:04:12 SMTP ERROR: Failed to connect to server: An attempt was made to access a socket in a way forbidden by its access permissions. (10013)
SMTP Error: Could not connect to SMTP host.

Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not connect to SMTP host. in D:\xampp\htdocs\scrap-bike\vendor\phpmailer\phpmailer\src\PHPMailer.php:2214 Stack trace: #0 D:\xampp\htdocs\scrap-bike\vendor\phpmailer\phpmailer\src\PHPMailer.php(2003): PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array) #1 D:\xampp\htdocs\scrap-bike\vendor\phpmailer\phpmailer\src\PHPMailer.php(1662): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Fri, 2 Se...', 'VGhpcyBpcyBhIHR...') #2 D:\xampp\htdocs\scrap-bike\vendor\phpmailer\phpmailer\src\PHPMailer.php(1500): PHPMailer\PHPMailer\PHPMailer->postSend() #3 D:\xampp\htdocs\scrap-bike\mail.php(38): PHPMailer\PHPMailer\PHPMailer->send() #4 {main} thrown in D:\xampp\htdocs\scrap-bike\vendor\phpmailer\phpmailer\src\PHPMailer.php on line 2214


source https://stackoverflow.com/questions/73587073/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissi

No comments:

Post a Comment