I'm trying to get send an Email from my gmail account with PHPMailer. But when running the php-script on my localhost I get the following error:
SERVER -> CLIENT: 530 5.7.0 Must issue a STARTTLS command first. m12sm23971137wrp.61 - gsmtp.
This is my code:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;
$mail->SMTPDebug = SMTP::DEBUG_CONNECTION;
$mail->Debugoutput = "html";
$mail->Host = gethostbyname('smtp.gmail.com');
$mail->Port = '587';
$mail->isHTML();
$mail->Username='myemail@gmail.com';
$mail->Passwort='gmail app-password';
$mail->SetFrom('myemail@gmail.com');
$mail->Subject = 'Hello';
$mail->Body='Test';
$mail->addAddress('otheremail@gmail.com');
if($mail->send()){
echo "sent";
} else {
echo "not sent".$mail->ErrorInfo;
}
I already tried a lot but nothing worked. Hope somone can help here :)