无法重新声明PHPMailerAutoload()


Cannot redeclare PHPMailerAutoload()?

我开始实现向大量用户发送电子邮件的功能,当我点击帖子时,我会收到以下错误。

无法在第31行的C:''examplep''htdocs''bloodbank2''phpmailer''PHPMailerAutoload.php中重新声明PHPMailerAutoload()

然而,数据库中的第一个用户能够接收电子邮件,而其他用户则不能。

这是我的密码
第一个是news.php,它允许人们发布新闻。

          <?php include 'core/init.php'; ?>
          <?php include 'includes/overall/oheader.php'; 
          if (empty($_POST) === false){
           $require_fields = array('heading', 'information');
           foreach($_POST as $key=>$value){
            if(empty($value) && in_array($key, $require_fields) === true){
                    $errors[] = 'Fields marked with an asterisk are  required';
                    break 1;
            }
            }
            }
            if(isset($_GET['success']) && empty($_GET['success'])){
            echo 'information posted';
            }else{

            if(empty($_POST) === false && empty($errors) === true){
            $insert_data = array(
                'heading'       => $_POST['heading'],
                'information'       => $_POST['information']

            );
            //
            //redirect
                    mail_users($_POST['heading'], $_POST['information']);   
                    header('Location: news.php?success');
                    news_data($insert_data);
                    //exit
                    exit();

        }

        ?>
        <h1>News</h1>
        <p>Just a Template</p>  


           <form action="" method="post">
            <ul>
                <li>
                    Heading*:<br>
                    <textarea rows="2" cols="40"  name="heading"maxlength="50"></textarea>
                </li>
                <li>

                    information*:<br>
                    <textarea rows="10" cols="40"  name="information"> </textarea>
                </li>
                <li>

                    <input type="submit" value="Post" name="save">
                </li>
            <ul>

        <?php 
        }
        include 'includes/overall/ofooter.php'; ?>

第二个代码是函数函数mail_user();

         function mail_users($subject, $body){
          $query = mysql_query("SELECT `email`, `first_name` FROM `users`");
          while(($row = mysql_fetch_assoc($query)) !== false){
           $body = "Hello" . $row['first_name'] . ",'n'n" . $body;
           email($row['email'], $subject, $body);

          }
         }

第三个是a包含php mailer的电子邮件功能。

             function email($to, $subject, $body){
              require '/phpmailer/PHPMailerAutoload.php';
              require '/phpmailer/class.phpmailer.php';
              error_reporting(-1);
              $mail = new PHPMailer(true);
              $mail->SMTPDebug = 0;                               // Enable verbose debug output
              $mail->isSMTP(true);                                      // Set mailer to use SMTP
              $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
              $mail->SMTPAuth = true;                               //             Enable SMTP authentication
              $mail->Username = '';                 // SMTP username
              $mail->Password = '';                           // SMTP password
              $mail->SMTPSecure = 'tls';                            //         Enable TLS encryption, `ssl` also accepted
              $mail->Port = 587;                                    // TCP port to connect to
              $mail->setFrom('');
              $mail->addAddress(''.$to.'');     // Add a recipient
              $mail->isHTML(true);                                  // Set Email format to HTML
              $mail->Subject = ''.$subject.'';
                $mail->Body    = ''.$body.'';
               $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
                if(!$mail->send()) {
                 echo 'Message could not be sent.';
                  echo 'Mailer Error: ' . $mail->ErrorInfo;
                  } else {
                echo 'Message has been sent';
                 }
               }

那么我该如何消除这个错误,让数据库中的每个人都能收到邮件呢?

您应该只需要自动加载器,因为它也会加载php mailer类:

require_once('/phpmailer/PHPMailerAutoload.php');
// remove this as it will be loaded by the autoloader
// require '/phpmailer/class.phpmailer.php';

同时将其移动到php文件的顶部。。不在函数中

相关文章:
  • 没有找到相关文章