malefy35
malefy35

Reputation: 31

php - "Undefined type 'PHPMailer\PHPMailer\PHPMailer'.intelephense(1009)" when in vscode

I'm currently trying to setup a simple PMP mailer script, however I'm getting an error "Undefined type 'PHPMailer\PHPMailer\PHPMailer'.intelephense(1009)" on line 14 of the code. So the code cannot be ran yet.

I started using PMPMailer last night and not really sure how to solve this problem. Could the problem be that my PHPMailer is in a different drive? To clarify I am trying to use this code in Visual Studio Code.

<?php
use PHPMailer\PHPMailer\PHPMailer;

if(isset($_POST['name']) && isset($_POST['email'])){
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $body = $_POST['body'];

    require_once "PHPMailer/PHPMailer.php";
    require_once "PHPMailer/SMTP.php";
    require_once "PHPMailer/Exception.php";

    $mail = new PHPMailer(true);

    //smtp settings
    $mail->isSMTP();
    $mail->Host = "smtp.gmail.com";
    $mail->SMTPAuth = true;
    $mail->Username = "[email protected]";
    $mail->Password = 'yourpassword';
    $mail->Port = 465;
    $mail->SMTPSecure = "ssl";

    //email settings
    $mail->isHTML(true);
    $mail->setFrom($email, $name);
    $mail->addAddress("[email protected]");
    $mail->Subject = ("$email ($subject)");
    $mail->Body = $body;

    if($mail->send()){
        $status = "success";
        $response = "Email is sent!";
    }
    else
    {
        $status = "failed";
        $response = "Something is wrong: <br>" . $mail->ErrorInfo;
    }

    exit(json_encode(array("status" => $status, "response" => $response)));
}

Upvotes: 1

Views: 3191

Answers (1)

malefy35
malefy35

Reputation: 31

The problem I found was Intelephense simply giving me a false error.

Upvotes: 1

Related Questions