Skip to content
Advertisement

phpmailer has authentcation problems

I have this error with my Authentication unsuccessful, and I can’t seem to find why I can’t sent a mail. To me everything looks good, but I can’t find this error.

Authentication unsuccessful

My php code:

<?php
    require 'PHPMailer-master/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    $mail ->IsSmtp();
    $mail ->SMTPDebug = 2;    
    $mail->SMTPOptions = array(
    'ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
    )
    );
    $mail ->SMTPAuth = true;
    $mail ->SMTPSecure = "tls";
    $mail ->Host = "smtp.office365.com";
    $mail ->Port = 587; // or 587
    $mail ->IsHTML(true);
    $mail ->Username = "test@xxx.com";
    $mail ->Password = "xxxx";
    $mail ->SetFrom("test@xxx.com");
    $mail ->FromName = "From";
    $mail ->Subject = "Prueba con PHPMailer";
    $mail ->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
    $mail ->AddAddress("test@xxxx.com");
    if(!$mail->Send())
    {
        echo "<br>Mail Not Sent<br>";
    }
    else
    {
        echo "<br>Mail Sent<br>";
    }
?>

Does anyone know why this is happening?

Advertisement

Answer

Try this code for outlook:

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.live.com";
$mail->SMTPAuth= true;
$mail->Port = 587;
$mail->Username= $account;
$mail->Password= $password;
$mail->SMTPSecure = 'tls';
$mail->From = $from;
$mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->addAddress($to);

Change variable with you access, for XAMPP config : here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement