Skip to content
Related Articles

Related Articles

Mailer multiple address in PHP

View Discussion
Improve Article
Save Article
  • Last Updated : 02 Nov, 2020
View Discussion
Improve Article
Save Article

In this article, we will be demonstrating how we can send the mail to the multiple addresses from the database using the PHP.

PHPMailer library is used to send any email safely from the unknown e-mail to any mail id using PHP code through XAMPP web-server for this project.

Installation process for all the pre-requisites mentioned in this How to send an email using PHPMailer link.

Prerequisite: The following PHP files are required for this project.

  • phpMailerautoLoad.php
  • phpMailer.php
  • OAuth.php
  • SMTP.php

Please follow the steps.

  1. Go to the htdocs of the xampp folder. Create the folder as shown in the image, then install the PHPMailer library into the that folder.

  2. Create the “index.php” file where the code implementation should be done.

  3. Create the database so that we can manually store the email_ID of the user.

  4. Create the dataBase=”mailer”

  5. Create the table names “users”

  6. PHP code:


    $conn= mysqli_connect("localhost"
                    "root", "", "mailer");
    require "PHPMailer.php";
    require "SMTP.php" ;
    require "PHPMailer-master/src/Exception.php" ;
    // Server settings
    $mail = new PHPMailer\PHPMailer\PHPMailer();
    // Enable verbose debug output
    // Send using SMTP
    $mail->Host = "";
    $mail->SMTPAuth = true;
    // SMTP username
    $mail->Username = "YOUR SMTP USERNAME"
    // SMTP password                   
    $mail->Password = "YOUR PASSWORD";
    $mail->SMTPAuth = "tls";
    $mail->Port = 587;           
    // This email-id will be taken
    // from your database
    // Selecting the mail-id having
    // the send-mail =1
    $sql = "select * from users where send_mail=1";
    // Query for the makeing the connection.
    $res = mysqli_query($conn, $sql);
    if(mysqli_num_rows($res) > 0) {
        while($x = mysqli_fetch_assoc($res)) {
        // Set email format to HTML
        $mail->Subject = 
            "Mailer Multiple address in php";
        $mail->Body = "Hii </p>Myself </h1>Rohit 
        sahu</h1> your Article has been acknowledge 
        by me and shortly this article will be 
        contributing in</p> <h1>Geeks for Geeks !</h1>";
        $mail->AltBody = "Welcome to Geeks for geeks";
           echo "Message has been sent check mailbox"
            echo "failure due to the google security";


    After executing the code, mails will be send to multiple ids.


    Email recieved by the user

    Multiple recievers at the same time.

    My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!