Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6864601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:55:55+00:00 2026-05-27T02:55:55+00:00

require_once(‘phpmailer/class.phpmailer.php’); function smtpmailer($to,$from,$subject,$body) { define(‘GUSER’, ‘xxx’); // Gmail username define(‘GPWD’, ‘xxx’); // Gmail password

  • 0
require_once('phpmailer/class.phpmailer.php');

function smtpmailer($to,$from,$subject,$body) { 
    define('GUSER', 'xxx'); // Gmail username
    define('GPWD', 'xxx'); // Gmail password
    printf("list:".$to);
    $recipient = array ($to);
    global $error;
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; 
    $mail->Username = GUSER;  
    $mail->Password = GPWD;           
    $mail->SetFrom($from, "Bank Negara");
    $mail->Subject = $subject;
    $mail->Body = $body;
    foreach ($recipient as $email){
    $mail->AddAddress($email);
    }
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }
}

I am passing a string which hold the email address in such format:

'email1@yahoo.com','email2@gmail.com'

When I am passing this

$recipient = array ($to);

I am having error Invalid address: But When I pass the string output directly like this:

$recipient = array ('email1@yahoo.com','email2@gmail.com');

It works fine. How should pass my $to String to this $recipient array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:55:56+00:00Added an answer on May 27, 2026 at 2:55 am
    $addresses = "'email1@yahoo.com','email2@gmail.com'";
    $to = array($addresses);
    

    is not going to magically create an array with two elements in it. What you’ll get is a SINGLE element in the array, e.g

    $to = array(
        0 => "'email1@yahoo.com','email2@gmail.com'"
    );
    

    However, doing

    $to = explode(',', $addresses);
    

    WILL give you a two element array:

    $to = array (
        0 => "...yahoo",
        1 => "...gmail"
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

require_once('classes/class.validation.php'); $array = $_POST['array']; $pass_profanity = false; $validation = new Validation; function check_for_profanity($input){ if(is_array($input)){
--- A.php ---- require_once 'B.php'; class A { public function __constructor($x){...} public function foo()
Is this a bad practice? like: function boo(){ require_once(class.moo.php); } ... ?
I have a function which uses: require_once(connect.php); function get_username($uid){ $stmt = $pdo->prepare(SELECT username FROM
require_once('/recaptcha/recaptchalib.php'); was in the correct place but the error says: Warning: require_once() [function.require-once]: open_basedir
Should I include/require_once the parent class that I am extending in PHP? for example
My problem: require_once '/includes/aws-sdk-1.5.2/sdk.class.php'; My environment: I have a pretty standard PHP site that
This is my code : <?php require_once 'classes/dbconnect.php'; $connector = new dbconnect(); pp(); function
My first class: <?php require_once( 'error/DisconnectedHandler.php' ); require_once( 'error/NoSuchRequestHandler.php' ); class NetworkManager { public
require_once('Class.php'); $myArray = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); // etc which is correct? foreach($myArray as $key => $val)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.