php - Fatal error: Cannot redeclare PHPMailerAutoload() -


i using phpmailer send emails local host.

i have written function supposed send emails registered users have chosen option receive them. (i.e. newsletter subscription, etc)

function email_users($subject, $body) {     include('core/db/db_connection.php');     $sql = "select email, first_name `_users` allow_email = 1";     $query = mysqli_query($dbcon, $sql);     while (($row = mysqli_fetch_assoc($query)) !== false) {         $body = "hello ". $row['first_name'] . ", <br><br>" . $body;         email($row['email'], $subject, $body);     } } 

the code calling function:

if (isset($_get['success']) === true && empty($_get['success']) === true) {         ?>             <h3 class="email_success">emails have been sent</h2>             <a href="admin.php" class="email_success_a">go admin page</a>         <?php          } else {             if (empty($_post) === false) {                 if (empty($_post['subject']) === true) {                     $errors[] = 'a message subject required.';                 }                 if (empty($_post['body']) === true) {                     $errors[] = 'a body message required.';                 }                 if (empty($errors) === false) {                     echo output_errors($errors);                 } else {                     email_users($_post['subject'], $_post['body']);                     header('location: email_users.php?success');                     exit();                 }             } // generate email form otherwise 

any idea why i'm getting error?

fatal error: cannot redeclare phpmailerautoload()

i point out error, function still works , emails being sent...

edit: requested, please see below function using phpmailer:

function email($user, $subject, $body) {     require 'phpmailer/phpmailerautoload.php';     $mail = new phpmailer;   /* $mail -> host,username,password , other misc stuff     $mail->subject = $subject;     $mail->body    = $body;     $mail->altbody = $body; etc */ } 

if use

require 'phpmailer/phpmailerautoload.php';

in function, call function 2 times, redeclare class. use require_once() instead.

require_once('phpmailer/phpmailerautoload.php'); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -