0

I want to send mail to different mail to different users. But can only send one mail and then page shows HTTP ERROR 500

I can receive a single mail and then in my log it shows

PHP Fatal error: Cannot redeclare sendMail() (previously declared

I have tried $mail->ClearAllRecipients(); And $mail->ClearAddresses(); as mentioned PHPmailer - Multiple sending of e-mail

$mail->ClearAllRecipients(); 
$mail->setFrom('mail@domain.com', 'Mailer');
$mail->addAddress('mail@info.com', 'Joe User');
$mail->addAddress('mail@info.com');
$mail->addReplyTo('info@example.com', 'Information');

Data which is meant to be sent as email body is in array format stored in session.

[P54] => Array
    (
        [0] => Array
            (
                [id] => 54
                [type] => Package
                [values] => Array
                    (
                        [0] => Array
                            (
                                [name] => Farmaan Mansoori
                                [email] => info@demo.com
                                [phone] => 425698745
                                [date_book] => 2018-09-20
                                [adults] => 1
                                [child] => 0
                                [infant] => 0
                                [room] => 0
                                [suppliment] => no
                                [hotel] => 3 Star
                                [img] => London Paris.jpg
                                [price] => Array
                                    (
                                        [0] => 3540
                                        [1] => 3100
                                        [2] => 2635
                                        [3] => 1
                                        [4] => 440
                                    )

                                [package_name] => london_paris
                                [id] => 54
                                [type] => Package
                            )

                    )

            )

    )

Can someone tell where am going wrong. So, I can mail different user different data which is intended for them.

Edit:

Complete Mail Code

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';    
$mail = new PHPMailer(true);
     try {
        $mail->SMTPDebug = 0;      
        $mail->isSMTP();        
        $mail->Host = 'smtp.gmail.com'; 
        $mail->SMTPAuth = true;         
        $mail->Username = 'demo@gmail.com'; 
        $mail->Password = 'secret';                          
        $mail->SMTPSecure = 'tls';                           
        $mail->Port = 587;                                   

        //Recipients
        $mail->ClearAllRecipients(); 
        $mail->setFrom('dmeo@gmail.com', 'Mailer');
        $mail->addAddress('info@techyogiitsolutions.com', 'Joe User');
        $mail->addAddress('demo@gmail.com');       
        $mail->addReplyTo('demo@example.com', 'Information');
        $mail->isHTML(true);                                  
        $mail->Subject = "$pname Tour Booking Details";
        $mail->Body    = "Hey! $name <br> You just booked a $pname . Here are some order details. <br>Adults: $adults <br> Child: $child <br> Infant: $infant <br> Hotel Type: $hotel <br> Single Rooms: $single <br> Total: $total.";
        $total = number_format($total);
        $mail->AltBody = "Hey! $name You just booked a $pname . Here are some order details.Adults: $adults Child: $child Infant: $infant Hotel Type: $hotel Single Rooms: $single Total: € $total.";
        $mail->send();
        $mail->ClearAddresses();
        } catch (Exception $e) {
            echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
        }
        $mail->ClearAllRecipients();

PHP Fatal error: Cannot redeclare sendMail() (previously declared in C:\Inetpub\vhosts\glox\httpdocs\rightinteract\global\mailer.php:12) in C:\Inetpub\vhosts\glox.com\httpdocs\rightinteract\global\mailer.php on line 12

2 Answers2

0

As suggested by Alex. I was using require in the loop which is causing issue of

PHP Fatal error: Cannot redeclare sendMail()

So I replace require with require_once which resolved the issue.

Thanks for the help Alex :)

-1

Check if in your gmail's configuration, your smtp has been enabled. https://mail.google.com/mail/u/0/#settings/general

https://support.google.com/mail/answer/7126229?visit_id=636723596479169047-2091026498&hl=pt-BR&rd=1

Elson Costa
  • 118
  • 1
  • 6