Jump to content

Email


mark110384

Recommended Posts

Hey guys, I'm trying to email a table created from an array, any suggestions on how I can do that, at present the email is sent the number of times that a record is found, for exaple three records will generate three emails. Any suggestions would be appreciated.

Link to comment
Share on other sites

Here you go guys,

 

          $result = mysql_query($sql);

 

while($myrow = mysql_fetch_array($result))

{

$itemId = $myrow['itemId'];

$price = $myrow['price'];

$quantity = $myrow['qty'];

$date = $myrow['date'];

 

 

 

$mailcontent = "Item Id: ".$itemId."\n"

  ."Quantity: ".$quantity."\n"

  ."Date: " .$date."\n"

          ."Customer email: ".$email."\n"

        ."Shipping Address: \n" .$shipadd."\n";

 

 

 

}

 

mail($to, $subject, $mailcontent,$additional_headers);

 

 

//at present it post the last result

Link to comment
Share on other sites

$i = 1;

while($myrow = mysql_fetch_array($result))
                     {
                        $itemId = $myrow['itemId'];
                        $price = $myrow['price'];
                        $quantity = $myrow['qty'];
                        $date = $myrow['date'];
               
                        
                     
                     $mailcontent.$i = "Item Id: ".$itemId."\n"
                                ."Quantity: ".$quantity."\n"
                                ."Date: " .$date."\n"
                                        ."Customer email: ".$email."\n"
                                   ."Shipping Address: \n" .$shipadd."\n";
                               
                     $i++;
                                                        
                        }
$mailcontent = $mailcontent1.$mailcontent2.$mailcontent3;
//etc
mail($to, $subject, $mailcontent,$additional_headers);

 

Something along those lines.

No expert myself!!

Link to comment
Share on other sites

$result = mysql_query($sql);
               
                  while($myrow = mysql_fetch_array($result))
                     {
                        $itemId = $myrow['itemId'];
                        $price = $myrow['price'];
                        $quantity = $myrow['qty'];
                        $date = $myrow['date'];
               
                        
                     
                     $mailcontent.= "Item Id: ".$itemId."\n"
                                ."Quantity: ".$quantity."\n"
                                ."Date: " .$date."\n"
                                        ."Customer email: ".$email."\n"
                                   ."Shipping Address: \n" .$shipadd."\n";
                               
                     
                                                        
                        }
                        
      mail($to, $subject, $mailcontent,$additional_headers);

Link to comment
Share on other sites

Hey thanks for the input guys but Ive found a soloution to the problem

 

$i = 1;

$mailcontent = "";

while($myrow = mysql_fetch_assoc($result))

{

$itemId = $myrow['itemId'];

$price = $myrow['price'];

$quantity = $myrow['quantity'];

$date = $myrow['createdate'];

 

if ($i ==1){

$mailcontent = "Date:" . $date."\n"

  ."Customer Email: " . $email . "\n"

  ."Shipping Address: " . $shipadd."\n\n";

  }

$mailcontent .= "Item Id: ".$itemId."\n"

  ."Quantity: ".$quantity."\n\n";

 

$i++;

 

 

}

 

mail($to, $subject, $mailcontent,$additional_headers);

}

Link to comment
Share on other sites

ummm...i don't really see how what you've done will work. your previous $mailcontent is still being written over every single loop iteration. 

 

Did you try my code? You said that everything works fine except all you're getting is the info from the last loop. That's because your overwriting the data every single time. All I did to that code was add a dot before the = in your $mailcontent assignment, so it concats the new info onto the previous info...which is what you 1/2 did right there.  You broke it up and used the dot but on the next loop iteration, your first = will just overwrite it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.