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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:11:25+00:00 2026-06-10T12:11:25+00:00

So i have this code that works perfectly without the ‘file attachment’ and sends

  • 0

So i have this code that works perfectly without the ‘file attachment’ and sends messages typed in a html to all recipients in a MYSQL DB but when i do slot in the attachment codes, the mail gets sent but to only one recipient. Please help me out 🙂

<html>
<head>
<title>test</title>
</head>
<body>

<?

mysql_connect("localhost", "root", "mypass") or die("Could not connect: " . mysql_error());

mysql_select_db("mydb");

$sql = mysql_query("SELECT * FROM mytable");

while($row = mysql_fetch_array($sql)){

$email = $row["email"];
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);

//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));

$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";

$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";

$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
}
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
    $strFilesName = $_FILES["fileAttach"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
    $strHeader .= "--".$strSid."\n";
    $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
    $strHeader .= "Content-Transfer-Encoding: base64\n";
    $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
    $strHeader .= $strContent."\n\n";
}


$flgSend = @mail($email,$strSubject,null,$strHeader);  // @ = No Show Error //

if($flgSend)
{
    echo "Task Complete. Your emails are being forwareded to your clients";
}
else
{
    echo "Error!!! Task incomplete. Please contact website maintainer.";
}
?>
</body>
</html>
  • 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-06-10T12:11:27+00:00Added an answer on June 10, 2026 at 12:11 pm

    You are not sending the email within your while loop.

    $strHeader .= $strMessage."\n\n";
    } //This is the end of your while loop
    //*** Attachment ***//
    if($_FILES["fileAttach"]["name"] != "")
    {
    

    So your code should look like this:

    <html>
    <head>
    <title>test</title>
    </head>
    <body>
    
    <?
    
    mysql_connect("localhost", "root", "mypass") or die("Could not connect: " . mysql_error());
    
    mysql_select_db("mydb");
    
    $sql = mysql_query("SELECT * FROM mytable");
    
    while($row = mysql_fetch_array($sql)){
    
    $email = $row["email"];
    $strSubject = $_POST["txtSubject"];
    $strMessage = nl2br($_POST["txtDescription"]);
    
    //*** Uniqid Session ***//
    $strSid = md5(uniqid(time()));
    
    $strHeader = "";
    $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
    
    $strHeader .= "MIME-Version: 1.0\n";
    $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
    $strHeader .= "This is a multi-part message in MIME format.\n";
    
    $strHeader .= "--".$strSid."\n";
    $strHeader .= "Content-type: text/html; charset=utf-8\n";
    $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
    $strHeader .= $strMessage."\n\n";
    //********************* This is the old end of while loop}
    //*** Attachment ***//
    if($_FILES["fileAttach"]["name"] != "")
    {
        $strFilesName = $_FILES["fileAttach"]["name"];
        $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
        $strHeader .= "--".$strSid."\n";
        $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
        $strHeader .= "Content-Transfer-Encoding: base64\n";
        $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
        $strHeader .= $strContent."\n\n";
    }
    
    
    $flgSend = @mail($email,$strSubject,null,$strHeader);  // @ = No Show Error //
    
    if($flgSend)
    {
        echo "Task Complete. Your emails are being forwareded to your clients";
    }
    else
    {
        echo "Error!!! Task incomplete. Please contact website maintainer.";
    }
    
    } // New end of while loop
    ?>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this .htaccess code that works perfectly: <IfModule mod_rewrite.c> RewriteEngine on RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$
I have this code that works in a unit test but doesn't work when
I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
I have this piece of code that works fine in subsonic 2.2, I migrated
I have the following code: Bear in mind that while this code works on
I have the this code that will create excel file and work sheet then
I have this code that reads from XML file. It gets five strings (groupId,
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code that runs but never stops. class A { public static

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.