topflight Posted April 9, 2009 Share Posted April 9, 2009 Hey I am trying to create a mass email system. I put the email info like $to $message and so on in the loop but it doesn't send the email. May I please have some examples on how to do this thanks. Link to comment https://forums.phpfreaks.com/topic/153401-creating-mass-email-system/ Share on other sites More sharing options...
Cory94bailly Posted April 9, 2009 Share Posted April 9, 2009 Upload your script and we will see the problems. Link to comment https://forums.phpfreaks.com/topic/153401-creating-mass-email-system/#findComment-805937 Share on other sites More sharing options...
topflight Posted April 9, 2009 Author Share Posted April 9, 2009 <?php //db info here if(isset($_POST['submit'])){ if((!$amessg | !$asub)){ echo'You are missing some required information please go back and fill out all the required information'; } else { $sql = mysql_query("SELECT * FROM members ORDER BY 'id' ASC"); $result = mysql_fetch_assoc($sql); $email = $result["email"]; for ($index=0; $index < count($email); $index++) { $to = 'sdomain';domain.org>'; $headers .= "Bcc: $email"; $message = "$ameesg"; $subject = "$asub"; mail($to,$subject, $message, $headers); ?> Link to comment https://forums.phpfreaks.com/topic/153401-creating-mass-email-system/#findComment-805940 Share on other sites More sharing options...
AdRock Posted April 9, 2009 Share Posted April 9, 2009 I don't know if this will help you but I send html/plain text emails as newsletters I save the newsletter content in the database, get it and put it into the function function sendHTMLemail($plain_text,$HTML,$from,$to,$subject) { // First we have to build our email headers // Set out "from" address $boundary = uniqid(time()); $headers = "MIME-Version: 1.0\r\n"; $headers .= "From: " . $from . "\r\n"; $headers .= "Subject: " . $subject . "\r\n"; $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n"; $message = "This is a MIME encoded message."; $message .= "\r\n\r\n--" . $boundary . "\r\n"; $message .= "Content-type: text/plain;charset=utf-8\r\n\r\n"; $message .= $plain_text; $message .= "\r\n\r\n--" . $boundary . "\r\n"; $message .= "Content-type: text/html;charset=utf-8\r\n\r\n"; $message .= $HTML; $message .= "\r\n\r\n--" . $boundary . "--"; // And then send the email .... if(mail($to, $subject, $message, $headers)) { return 'Correct'; } else { return 'Email not sent'; } } function send_newsletter($id) { global $host,$dbUser,$dbPass,$dbName; require_once("../php/database/connection.php"); require_once("../php/database/MySQL.php"); $db = & new MySQL($host,$dbUser,$dbPass,$dbName); $sql="SELECT id, DATE_FORMAT(date, '%D %M %Y') as date, welcome, article1_title, article1, article1_link, article2_title, article2, article2_link, article3_title, article3, article3_link,article4_title, article4, article4_link, article5_title, article5, article5_link FROM newsletters WHERE id=$id"; // Perform a query getting back a MySQLResult object $result = $db->query($sql); while ($row = $result->fetch()) { $data['id'] = $row['id']; $subject = $row['article1_title']; $data['date'] = $row['date']; $data['welcome'] = html_entity_decode($row['welcome']); if(!empty($row['article1_title'])) { $data['article1_title'] = strtoupper($row['article1_title']); $data['article1'] = $row['article1']; $data['article1_link'] = $row['article1_link']; } if(!empty($row['article2_title'])) { $data['article2_title'] = strtoupper($row['article2_title']); $data['article2'] = $row['article2']; $data['article2_link'] = $row['article2_link']; } if(!empty($row['article3_title'])) { $data['article3_title'] = strtoupper($row['article3_title']); $data['article3'] = $row['article3']; $data['article3_link'] = $row['article3_link']; } if(!empty($row['article4_title'])) { $data['article4_title'] = strtoupper($row['article4_title']); $data['article4'] = $row['article4']; $data['article4_link'] = $row['article4_link']; } if(!empty($row['article5_title'])) { $data['article5_title'] = strtoupper($row['article5_title']); $data['article5'] = $row['article5']; $data['article5_link'] = $row['article5_link']; } } $placeholders = array("{id}", "{date}", "{welcome}", "{article1_title}", "{article1}", "{article1_link}", "{article2_title}", "{article2}", "{article2_link}", "{article3_title}", "{article3}", "{article3_link}", "{article4_title}", "{article4}", "{article4_link}", "{article5_title}", "{article5}", "{article5_link}"); $HTML = ' <html> <body> <table width="100%" cellspacing="10" cellpadding="0"> <tr> <td align="center" valign="top"> <table width="580" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center" style="font-size:8pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"> <p>You\'re receiving this newsletter because you SIGNED UP AT <a href="http://www.yoursite.com">operationbraveheart.org.uk</a>.</p> <p>Not interested anymore? <a href="http://www.yoursite.com/php/unsubscribe/{email}">Unsubscribe Instantly</a>. Having trouble reading this email? <a href="http://www.yoursite.com/newsletter/{id}">View it in your browser</a>.</p> <br> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:1px solid; #000000;"> <tr> <td height="117" valign="bottom" align="left" class="header"> <a href="http://www.yoursite.com/"><img src="http://www.yoursite.com/images/newsletter/layout/banner.jpg" width="580" height="117" border=0"" alt="Operation Braveheart" title="Operation Braveheart" /></a> </td> </tr> <tr> <td align="center"> <table width="550" cellspacing="0" cellpadding="0"> <tr> <td align="right" style="padding: 3px;font-weight: bold; font-size:12pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"><p>{date}</p></td> </tr> <tr> <td style="font-size:10pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"> <p><b>Hello {name}</b></p> <p>{welcome}</p> <br> </td> </tr> <tr align="left" valign="top"> <td width="550" valign="top" align="left" style="font-size:10pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"> <table cellspacing="0" cellpadding="4"> <tr> <td style="color: #ff891a;font-family: Arial, Verdana, Times, sans-serif;"> <h2 style=" margin: 0; font-size: 12pt;">{article1_title}</h2> </td> </tr> <tr> <td style="font-size:10pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;">{article1}</td> </tr>'; if(!empty($data['article1_link'])) { $HTML.=' <tr> <td align="right" style="font-size:9pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"><a href="{article1_link}">Read More...</a></td> </tr>'; } $HTML.=' </table> <br> <img src="http://www.yoursite.com/images/newsletter/layout/hr-big.gif" width="550" height="27" />'; if(!empty($data['article2'])) { $HTML.=' <table cellspacing="0" cellpadding="4"> <tr> <td style="color: #ff891a;font-family: Arial, Verdana, Times, sans-serif;"> <h2 style=" margin: 0; font-size: 12pt;">{article2_title}</h2> </td> </tr> <tr> <td style="font-size:10pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;">{article2}</td> </tr>'; if(!empty($data['article2_link'])) { $HTML.=' <tr> <td align="right" style="font-size:9pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"><a href="{article2_link}">Read More...</a></td> </tr>'; } $HTML.=' </table> <br> <img src="http://www.yoursite.com/images/newsletter/layout/hr-big.gif" width="550" height="27" />'; } if(!empty($data['article3'])) { $HTML.=' <table cellspacing="0" cellpadding="4"> <tr> <td style="color: #ff891a;font-family: Arial, Verdana, Times, sans-serif;"> <h2 style=" margin: 0; font-size: 12pt;">{article3_title}</h2> </td> </tr> <tr> <td style="font-size:10pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;">{article3}</td> </tr>'; if(!empty($data['article3_link'])) { $HTML.=' <tr> <td align="right" style="font-size:9pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"><a href="{article3_link}">Read More...</a></td> </tr>'; } $HTML.=' </table> <br> <img src="http://www.yoursite.com/images/newsletter/layout/hr-big.gif" width="550" height="27" />'; } if(!empty($data['article4'])) { $HTML.=' <table cellspacing="0" cellpadding="4"> <tr> <td style="color: #ff891a;font-family: Arial, Verdana, Times, sans-serif;"> <h2 style=" margin: 0; font-size: 12pt;">{article4_title}</h2> </td> </tr> <tr> <td style="font-size:10pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;">{article4}</td> </tr>'; if(!empty($data['article4_link'])) { $HTML.=' <tr> <td align="right" style="font-size:9pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"><a href="{article4_link}">Read More...</a></td> </tr>'; } $HTML.=' </table> <br> <img src="http://www.yoursite.com/images/newsletter/layout/hr-big.gif" width="550" height="27" />'; } if(!empty($data['article5'])) { $HTML.=' <table cellspacing="0" cellpadding="4"> <tr> <td style="color: #ff891a;font-family: Arial, Verdana, Times, sans-serif;"> <h2 style=" margin: 0; font-size: 12pt;">{article5_title}</h2> </td> </tr> <tr> <td style="font-size:10pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;">{article5}</td> </tr>'; if(!empty($data['article5_link'])) { $HTML.=' <tr> <td align="right" style="font-size:9pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"><a href="{article5_link}">Read More...</a></td> </tr>'; } $HTML.=' </table> <br> <img src="http://www.yoursite.com/images/newsletter/layout/hr-big.gif" width="550" height="27" />'; } $HTML.=' </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td width="580" height="30" background="http://www.yoursite.com/images/layout/footer-bg.gif"> <div style="font-size:8pt;color: #fff;font-family: Arial, Verdana, sans-serif;text-align: center;padding:3px;"> <ul style=" list-style-image:none;list-style-position:outside;list-style-type:none;margin:0;padding:0;"> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com">Home</a></li> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com/contact-us">Contact Us</a></li> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com/news/">News</a></li> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com/events/">Events</a></li> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com/blogs/">Blogs</a></li> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com/poems/">Poems</a></li> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com/sponsors/">Supporters</a></li> <li style="display:inline;margin:0;padding:0px 10px;text-align:center;"><a style="color:#FFFFFF" href="http://www.yoursite.com/guestbook/">Guestbook</a></li> </ul> <p style="margin:0">Copyright © 2008 Operation Braveheart. All Rights Reserved.</p> </div> <td> </tr> <tr> <td align="center" style="font-size:8pt; font-family: Arial, Verdana, Times, sans-serif; margin: 0;"> <p>Not interested anymore? <a href="http://www.yoursite.com/php/unsubscribe/{email}">Unsubscribe Instantly</a>. Visit us at <a href="http://www.yoursite.com">www.yoursite.com</a></p> </td> </tr> </table> </td> </tr> </table> </body> </html> '; $plain_text = "Hello {name} {welcome} {article1_title} {article1} "; if(!empty($data['article2_title'])) { $plain_text.="{article2_title} {article2} "; } if(!empty($data['article3_title'])) { $plain_text.="{article3_title} {article3} "; } if(!empty($data['article4_title'])) { $plain_text.="{article4_title} {article4} "; } if(!empty($data['article5_title'])) { $plain_text.="{article5_title} {article5} "; } $from = "Your site <[email protected]>"; $sql="SELECT name, email FROM mailinglist"; // Perform a query getting back a MySQLResult object $result = $db->query($sql); $items = array(); while ($row = $result->fetch()) { $items[] = array( 'email' => md5($row['email']), 'name' => ucwords($row['name']) ); } $nameholder = array("{name}"); $emailholder = array("{email}"); $HTML = str_replace($placeholders, $data, $HTML); $plain_text = str_replace($placeholders, $data, $plain_text); foreach($items as $item) { $to = $item['email']; $HTML = str_replace($nameholder, $item['name'], $HTML); $HTML = str_replace($emailholder, $item['email'], $HTML); $plain_text = str_replace($nameholder, $item['name'], $plain_text); $result = sendHtmlEmail($plain_text,$HTML,$from,$to,$subject); if($result != 'Correct') { return "Emails not sent"; } } } Link to comment https://forums.phpfreaks.com/topic/153401-creating-mass-email-system/#findComment-805957 Share on other sites More sharing options...
topflight Posted April 9, 2009 Author Share Posted April 9, 2009 mines if different I want the email to send what ever the user inputs in the message field of the form. Link to comment https://forums.phpfreaks.com/topic/153401-creating-mass-email-system/#findComment-805959 Share on other sites More sharing options...
MadTechie Posted April 10, 2009 Share Posted April 10, 2009 Erm.. to who ? $to = 'sdomain';domain.org>; should be $to = '[email protected]'; Link to comment https://forums.phpfreaks.com/topic/153401-creating-mass-email-system/#findComment-805986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.