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 6318497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:38:40+00:00 2026-05-24T15:38:40+00:00

im new to php and i need a bit of clarification. ive searched google

  • 0

im new to php and i need a bit of clarification. ive searched google but tooo many results, none clearly identify whats wrong with mine. since i dont get any errors im not sure whats happening.

the error im getting is this:

Warning: mail() expects parameter 1 to be string, array given in

so longstory short, this is a small bit of my code:

while( $sn_rowSelect = mysqli_fetch_array($sn_queryResult) ) { 
    mail($to,$subject,$mssg,'from:xyz');
}

if(mail($to,$subject,$mssg,'from:xyz')) {
echo "An e-mail was sent to $to with the subject: $subject";
} else {
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid";
}

what im trying to do is, i have a small database with names etc, with this loop above, its suppose to say that while theres a name in $sn_rowSelect, to feed it the message, essentially emailing the whole lot of emails.

the error says “expects string, array given’ im assuming means the name gotten from the DB is gotten as an assosiative array value, but, isnt that what its supposed to do?

thanks in advance.

EDIT***

$to = $sn_rowSelect;
$from = $_POST['sender'];
$mssg = $_POST['message'];

from and mssg, are filled out via a form on another page.

  • 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-24T15:38:40+00:00Added an answer on May 24, 2026 at 3:38 pm

    You must set the $to parameter inside the while loop, and you need to set it to a string. You will also need to move the if statement inside the while loop if you want it to make sense, and you can’t call mail() twice since that will create redundant emails.

    Here’s a fixed code for you:

    $from = $_POST['sender'];
    $mssg = $_POST['message'];
    
    while($sn_rowSelect = mysqli_fetch_array($sn_queryResult) ) {
        $to = sn_rowSelect['email']; //change 'email' to the name of column in db
        $mailstatus = mail($to, $subject, $mssg, 'from:xyz');
    
        if($mailstatus) {
            echo "An e-mail was sent to $to with the subject: $subject\n";
        }else{
            echo "There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid\n";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a bit new to sql and php so I need some help
I am a bit new to PHP OOP so I need you guys help
I am a bit new to php and I need to create a quiz
Hello new to PHP and in a bit of a bind. I need to
I'm new to php and I need a hand. I have width by height
I am new to PHP. I need to GET a xml stored locally using
I'm new to PHP so I don't know whether this is possible. I need
Im new to JSON and php. I need to grab the lat and lng
This question may seem a bit stupid, but i'm new to Joomla! And i
I am facing a bit of a quandary, I need to replace a new

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.