首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHPMailer错误:致命错误:未捕获错误:调用未定义的方法PHPMailer\PHPMailer\PHPMailer::isSTMP()

PHPMailer错误:致命错误:未捕获错误:调用未定义的方法PHPMailer\PHPMailer\PHPMailer::isSTMP()
EN

Stack Overflow用户
提问于 2018-05-13 18:04:33
回答 2查看 3.8K关注 0票数 1

我正在尝试发送邮件使用PHPMailer,但它显示我的错误。这是测试代码。当它完成时,我正在考虑将它添加到我的主代码中。但我不知道这段代码出了什么问题。它只是给了我这个错误。

这是错误:

致命错误:未捕获错误:调用中未定义的方法PHPMailer\PHPMailer\PHPMailer::isSTMP()

下面是我的代码:

代码语言:javascript
复制
<!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>
EN

回答 2

Stack Overflow用户

发布于 2019-03-11 20:48:42

你刚刚在typing.Here中犯了一个错误,你得到的错误是$mailer->isSTMP();将它改为$mailer->isSMTP();

票数 1
EN

Stack Overflow用户

发布于 2020-02-19 17:51:54

在V6.0以上的版本中使用以下代码

代码语言:javascript
复制
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Load Composer's autoloader
require 'vendor/autoload.php';

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = 'smtp1.example.com';                    // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'user@example.com';                     // SMTP username
    $mail->Password   = 'secret';                               // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
    $mail->Port       = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    // Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50314938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档