ninedoors Posted November 2, 2007 Share Posted November 2, 2007 I want to send people in my email database information that I have in there. Basically I am sending players in a hockey league player info through an email. I figured the easiest way to do this is by emailing them a table with the results of my database query in it. When I tried to do this using phpmailer I got very lost. Everything is fine except I'm not sure how to structure the code inside the $body variable so that it will show up in the email. Here is the code I am using, <?php require("class.phpmailer.php"); require("class.smtp.php"); require("phpmailer.lang-en.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "localhost"; // SMTP server $mail->SMTPAuth = "true"; // turn on SMTP authentication $mail->Username = "nick@barriemenshockey.com"; // SMTP username $mail->Password = "******"; // SMTP password*/ include 'mailconfig.php'; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $mail->From = "nick@barriemenshockey.com"; $mail->FromName = "Barrie Mens Hockey League"; // HTML body $body = "Hey guys, <p>"; $body .= "Sorry about the delay in getting you your rosters but here they are, <br>"; $body .= $query1 = "SELECT name, teamname, jerseynumber, email, phonenumber FROM playerstats WHERE teamname = 'Boomtown Blades' ORDER BY jerseynumber "; $result1 = mysql_query($query1); $rows =mysql_fetch_assoc($result1); //set up the table: print("<table border=4 bordercolor = #184184 cellspacing=0 width=95% align=center><CAPTION><font size=4>Barrie Men's Hockey Roster 2007-08</font></CAPTION><tr>"); //print the proper column names in table headers: echo "\n<tr>". "\n\t<th width=25><font size=3>Name</font></th>". "\n\t<th width=30><font size=3>Team</font></th>". "\n\t<th width=30><font size=3>#</font></th>". "\n\t<th width=60><font size=3>Email</font></th>". "\n\t<th width=30><font size=3>Phone #</font></th>". "\n</tr>"; //loop through the table, printing //the field values in table cells: do { print("<tr>"); foreach($rows as $key=>$value) { print("<td><center>$value</center></td>"); } print("</tr>"); } while ($rows = mysql_fetch_assoc($result1)); //close out the table: print("</tr></table>"); $body .= "Sincerely, <p>"; $body .= "Nick and Rob"; //non-HTML body $textbody = "Hey " . $row['name'] . ", \n\n"; $textbody .= "Check for hmtl first" $textbody .= "Sincerely, \n"; $textbody .= "Nick and Rob"; $mail-> Subject = "BMHL Rosters"; $mail-> Body = $body; $mail -> AltBody = $textbody; $mail->AddAddress("nick@barriemenshockey.com"); $mail-> WordWrap = 50; if(!$mail->Send()) { echo "There has been a mail error sending to " . $row["email"] . "<br>"; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } // Clear all addresses and attachments for next loop $mail->ClearAddresses(); ?> I am using my email address to test it if you are wondering. Thanks for any help. Nick Quote Link to comment https://forums.phpfreaks.com/topic/75713-code-inside-phpmailer/ Share on other sites More sharing options...
Moon-Man.net Posted November 2, 2007 Share Posted November 2, 2007 What is happening? Examples? Quote Link to comment https://forums.phpfreaks.com/topic/75713-code-inside-phpmailer/#findComment-383192 Share on other sites More sharing options...
poe Posted November 2, 2007 Share Posted November 2, 2007 email -> as in barrie colts? Quote Link to comment https://forums.phpfreaks.com/topic/75713-code-inside-phpmailer/#findComment-383211 Share on other sites More sharing options...
ninedoors Posted November 2, 2007 Author Share Posted November 2, 2007 Poe: Yes as in the barrie colts. Moon: Examples, what do you mean, I am using the script above to send an email to everyone on the given team. I want to know the format to use a html table in the email. Quote Link to comment https://forums.phpfreaks.com/topic/75713-code-inside-phpmailer/#findComment-383217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.