使用PHPMailer发送邮件报错:调用未定义方法isSTMP()求助
Hey, let's break down what's going on here and get your email sending working smoothly.
The Root Cause
That fatal error Fatal error: Uncaught Error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::isSTMP() is a simple typo. The correct method name in PHPMailer for enabling SMTP is isSMTP()—you accidentally wrote isSTMP() (swapped the M and T in SMTP) somewhere in your code, which the error log confirms.
Your Test Code
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php require "vendor/autoload.php"; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $developmentMode = true; $mailer = new PHPMailer($developmentMode); try { $mailer->SMTPDebug = 2; $mailer->isSMTP(); //edited here if ($developmentMode) { $mailer->SMTPOptions = [ 'ssl'=> [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ]; } $mailer->Host = 'smtp.gmail.com'; $mailer->SMTPAuth = true; $mailer->Username = "mygmail@gmail.com"; $mailer->Password = "password"; $mailer->SMTPSecure = 'tls'; $mailer->Port = 587; $mailer-> setFrom("mygmail@gmail.com", "Izaya"); $mailer->addAddress("anothergmail@gmail.com","orihara"); $mailer->isHTML(true); $mailer->Subject = "Hey There"; $mailer->Body = "NICE TO MEET YOU IZAYA "; $mailer->send(); $mailer->ClearAllRecipients(); echo "Mail has been Sent"; }catch (Exception $e) { echo "Email Error.INFO:" . $mailer->ErrorInfo; } ?> </body> </html>
Fixes & Next Steps
I see you already edited the line to isSMTP() (marked with //edited here)—that's exactly the fix for the typo error. But if you still run into issues, check these common pitfalls:
- Composer Installation: Make sure you installed PHPMailer correctly via Composer, and the
vendor/autoload.phppath is accurate. - Gmail SMTP Quirks:
- Gmail no longer allows regular account passwords for SMTP access unless you enable 2-step verification and generate an App Password (use this instead of your regular password).
- Your current settings for
Host = 'smtp.gmail.com',SMTPSecure = 'tls', andPort = 587are correct—don't change those.
- Method Call Spacing: You have an extra space in
$mailer-> setFrom(...)—remove the space between->andsetFromto make it$mailer->setFrom(...); this could cause unexpected issues.
Pro Tip
Leaving SMTPDebug = 2 enabled in development is smart—it will print detailed SMTP connection logs, which is super helpful for troubleshooting any future authentication or delivery problems.
内容的提问来源于stack exchange,提问作者Izaya

