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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:17:41+00:00 2026-05-23T18:17:41+00:00

I am trying to email values from a MySQL database to a user when

  • 0

I am trying to email values from a MySQL database to a user when prompted. I cannot seem to pass the information off to the body of the email message with the correct values. Here is a code sample:

mysql_connect ("host","name","pass")  or die (mysql_error());
mysql_select_db ("db_name");

$sql = mysql_query("select * from table_name where id = '$id'");
//$id is previously defined as the users id 
while ($row = mysql_fetch_array($sql)){
$title = $row["title"];
}

$email = 'user@email.com'
$subject = "Titles";
$body = "Title: " . $title;

if (mail($email, $subject, $body)) {
echo("<p>successfully sent. "</p>");
} else {
echo("<p>delivery failed...</p>");
}

I have tried running an array in the while loop to get the title values to display, but again I cannot seem to get these values to carry over to the email message.

This is assuming that each user has multiple titles being sent to them. Ideally, the final email message would be something like:

Title: Title1
Title: Title2
Title: Title3
Title: Title4
Title: Title5

and continue on for however many titles are in the array. Thanks for any assistance.

  • 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-23T18:17:42+00:00Added an answer on May 23, 2026 at 6:17 pm
    mysql_connect ("host","name","pass")  or die (mysql_error());
    mysql_select_db ("db_name");
    
    $body = '';  // start with empty string
    
    $sql = mysql_query("select * from table_name where id = '$id'");
    //$id is previously defined as the users id 
    while ($row = mysql_fetch_assoc($sql))
    {
         $body .= 'Title: ' . $row['title'] . "\n";
    }
    
    $email = 'user@email.com'
    $subject = "Titles";
    // removed $body= ... 
    
    if (mail($email, $subject, $body)) {
    echo("<p>successfully sent. "</p>");
    } else {
    echo("<p>delivery failed...</p>");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i am tring to retrive user information from mysql database, i am getting
I'm trying to insert values from a form and insert it onto a MySQL
I am trying to run a query off of my mysql database using the
Im trying to pass some values into a text box from a child page
I am trying to send email using Exchange 2007 from a console app using
I'm trying to send an email in Java but when I read the body
I am trying to send an email from a site I am building, but
From MBUnit I am trying to check if the values of two objects are
I am trying to insert into mysql from an xml using PHP, but the
Trying to add email notification to my app in the cleanest way possible. When

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.