function send($mailid, $admin_user) { if (!check_admin_user($admin_user)) { return false; } if (!($info = load_mail_info($mailid))) { echo "Cannot load list information for message {$mailid}"; return false; } $subject = $info[0]; $listid = $info[1]; $status = $info[2]; $sent = $info[3]; $from_name = 'Pyramid MLM'; $from_address = 'return@address'; $query = "select email from sub_lists where listid = {$listid}"; $result = mysql_query($query); if (!$result) { echo $query; return false; } else { if (mysql_num_rows($result) == 0) { echo "There is nobody subscribed to list number {$listid}"; return false; } else { // include PEAR mail classes include 'Mail.php'; include 'Mail/mime.php'; // instantiate MIME class and pass it the carriage return/line feed // character used on this system $message = new Mail_mime("\r\n"); // read in the text version of the newsletter $textfilename = "archive/{$listid}/{$mailid}/text.txt"; $tfp = fopen($textfilename, "r"); $text = fread($tfp, filesize($textfilename)); fclose($tfp); // read in the HTML version of the newsletter $htmlfilename = "archive/{$listid}/{$mailid}/index.html"; $hfp = fopen($htmlfilename, "r"); $html = fread($hfp, filesize($htmlfilename)); fclose($hfp); // add HTML and text to the mimemail object $message->setTXTBody($text); $message->setHTMLBody($html); // get the list of images that relate to this message $query = "select path, mimetype from images where mailid = {$mailid}"; if (db_connect()) { $result = mysql_query($query); if (!$result) { echo '<p>Unable to get image list from database.'; return false; } $num = mysql_numrows($result); for ($i = 0; $i < $num; $i++) { //load each image from disk $imgfilename = "archive/{$listid}/{$mailid}/" . mysql_result($result, $i, 0); $imgtype = mysql_result($result, $i, 1); // add each image to the object $message->addHTMLImage($imgfilename, $imgtype, $imgfilename, true); } } // create message body $body = $message->get(); // create message headers $from = '"' . get_real_name($admin_user) . '" <' . $admin_user . '>'; $hdrarray = array('From' => $from, 'Subject' => $subject); $hdrs = $message->headers($hdrarray); // create the actual sending object $sender =& Mail::factory('mail'); if ($status == 'STORED') { // send the HTML message to the administrator $sender->send($admin_user, $hdrs, $body); // send the plain text version of the message to administrator mail($admin_user, $subject, $text, 'From: "' . get_real_name($admin_user) . '" <' . $admin_user . ">"); echo "Mail sent to {$admin_user}"; // mark newsletter as tested $query = "update mail set status = 'TESTED' where mailid = {$mailid}"; if (db_connect()) { $result = mysql_query($query); } echo '<p>Press send again to send mail to whole list.<center>'; display_button('send', "&id={$mailid}"); echo '</center>'; } else { if ($status == 'TESTED') { //send to whole list $query = "select subscribers.realname, sub_lists.email, \r\n subscribers.mimetype \r\n from sub_lists, subscribers \r\n where listid = {$listid} and \r\n sub_lists.email = subscribers.email"; if (!db_connect()) { return false; } $result = mysql_query($query); if (!$result) { echo '<p>Error getting subscriber list'; } $count = 0; // for each subscriber while ($subscriber = mysql_fetch_row($result)) { if ($subscriber[2] == 'H') { //send HTML version to people who want it $sender->send($subscriber[1], $hdrs, $body); } else { //send text version to people who don't want HTML mail mail($subscriber[1], $subject, $text, 'From: "' . get_real_name($admin_user) . '" <' . $admin_user . ">"); } $count++; } $query = "update mail set status = 'SENT', sent = now() \r\n where mailid = {$mailid}"; if (db_connect()) { $result = mysql_query($query); } echo "<p>A total of {$count} messages were sent."; } else { if ($status == 'SENT') { echo '<p>This mail has already been sent.'; } } } } } }
function send($mailid, $admin_user, $emailAddr) { if (!check_admin_user($admin_user)) { return false; } if (!($info = load_mail_info($mailid))) { echo "Cannot load list information for message {$mailid}"; return false; } $subject = $info['subject']; //$CI->email->subject($subject); $listid = $info['listid']; $status = $info['status']; $sent = $info['sent']; $from_name = 'Trimart'; $from_address = '*****@*****.**'; //$CI->email->from($from_address,$from_name); $query = "select email from sub_lists where listid =" . $listid; $conn = db_connect(); $result = $conn->query($query); if (!$result) { echo "No result"; return false; } else { if ($result->num_rows == 0) { echo "There is nobody subscribed to list number {$listid}"; return false; } } $mail = new PHPMailer(); $mail->IsSMTP(); // we are going to use SMTP $mail->SMTPAuth = true; // enabled SMTP authentication $mail->SMTPSecure = "ssl"; // prefix for secure protocol to connect to the server $mail->Host = "smtp.gmail.com"; //"";192.168.20.202 // setting GMail as our SMTP server $mail->Port = 465; //;8089 // SMTP port to connect to GMail $mail->Username = "******"; //"andre.campbell#mcalbds"; // user email address $mail->Password = "******"; //"AC#220991"; // password in GMail // read in the text version of the newsletter $textfilename = APPPATH . "archive\\" . $listid . "\\" . $mailid . "\\text.txt"; if (file_exists($textfilename)) { $tfp = fopen($textfilename, "r"); $text = fread($tfp, filesize($textfilename)); fclose($tfp); } // read in the HTML version of the newsletter $htmlfilename = APPPATH . "archive\\" . $listid . "\\" . $mailid . "\\index.html"; if (file_exists($htmlfilename)) { $hfp = fopen($htmlfilename, "r"); $html = fread($hfp, filesize($htmlfilename)); fclose($hfp); } // get the list of images that relate to this message $query = "select path, mimetype from images where mailid = {$mailid}"; $result = $conn->query($query); if (!$result) { echo '<p>Unable to get image list from database.</p>'; return false; } $num = $result->num_rows; for ($i = 0; $i < $num; $i++) { //load each image from disk $row = $result->fetch_array(); $imgfilename = APPPATH . "archive\\{$listid}\\{$mailid}\\" . $row[0]; $imgtype = $row[1]; // add each image to the object //$message->addHTMLImage($imgfilename, $imgtype, $imgfilename, true); $mail->AddEmbeddedImage($imgfilename); // some attached files //$mail->AddAttachment("images/phpmailer_mini.gif"); // as many as you want } // create message body //$body = $message->get(); // create message headers $from = '"' . get_real_name($admin_user) . '" <' . $admin_user . '>'; $hdrarray = array('From' => $from, 'Subject' => $subject); //$hdrs = $message->headers($hdrarray); if ($status == 'STORED') { $mail->isHTML(true); $mail->Subject = $subjectf; $mail->AddAddress($_POST['emailAddr'], $admin_user); $sent = FALSE; // send the HTML message to the administrator //$sender->send($admin_user, $hdrs, $body); if ($html) { $mail->Body = $html; if (!$mail->Send()) { echo "Error sending html version: " . $mail->ErrorInfo; } } else { $sent = TRUE; } if ($sent) { echo "Mail sent to {$admin_user} with email address " . $_POST['emailAddr']; // mark newsletter as tested $query = "update mail set status = 'TESTED' where mailid = {$mailid}"; $result = $conn->query($query); echo '<p>Press send again to send mail to whole list.<center>'; display_button('send', "&id={$mailid}"); echo '</center></p>'; } //$mail->ClearAddresses(); } else { if ($status == 'TESTED') { $count = 0; $subscribers = get_subscribers($_GET['id']); $CI =& get_instance(); $row = $CI->trimart->get_login_credentials($user, $password); // for each subscriber /*for($i = 0; $i < count($subscribers); $i++) { $mail->AddAddress(subscriber[$i][0],$CI->trimart->get_real_name(subscriber[$i][0])); }*/ $mail->AddAddress('jamalbutcher2@gmail', 'YOU'); $mail->send(); $query = "update mail set status = 'SENT', sent = now() \n where mailid = {$mailid}"; $result = $conn->query($query); echo "<p>A total of {$count} messages were sent.</p>"; } else { if ($status == 'SENT') { echo '<p>This mail has already been sent.</p>'; } } } }
function send($mailid, $admin_user, $emailAddr) { $CI =& get_instance(); $CI->load->library('email'); /*$config['protocol'] = "smtp"; $config['smtp_host'] = "ssl://smtp.gmail.com"; //$config['smpt_timeout'] = '5'; //$config['smtp_user'] = "******"; //$config['smtp_pass'] = "******"; $config['smtp_port'] = 465;//"8089"; $config['charset'] = 'iso-8859-1'; $config['mailtype'] = "text"; $config['newline'] = "\r\n"; //$config['validation'] = TRUE;*/ //$config['protocol'] = 'smtp'; //$config['smtp_host'] = 'aspmx.l.google.com'; //change this //$config['smtp_port'] = '25'; //$config['smtp_user'] = '******'; //change this //$config['smtp_pass'] = '******'; //change this //$config['mailtype'] = 'text'; //$config['charset'] = 'iso-8859-1'; //$config['wordwrap'] = TRUE; //$config['newline'] = "\r\n"; //$CI->email->initialize($config); /*$CI->email->from('jamalbutcher@gmail', 'sender name'); $CI->email->to('jamalbutcher@gmail'); //$CI->email->cc('*****@*****.**'); $CI->email->subject('Your Subject'); $CI->email->message('Your Message'); //$CI->email->attach('/path/to/file1.png'); // attach file //$CI->email->attach('/path/to/file2.pdf'); if ($CI->email->send()) echo "Mail Sent!"; else echo "There is error in sending mail!";*/ ini_set('SMTP', 'smtp.gmail.com'); //192.168.20.202 ini_set('smtp_port', 25); //25 ini_set('sendmail_from', 'jamalbutcher@gmail'); //ini_set('smtp_user','jamalbutcher@gmail'); //ini_set('smptp_pass','P4m266a-mlx'); //ini_set('SMTP', '192.168.20.202'); // //ini_set('smtp_port', 8089); //25 if (!check_admin_user($admin_user)) { return false; } if (!($info = load_mail_info($mailid))) { echo "Cannot load list information for message {$mailid}"; return false; } $subject = $info['subject']; $CI->email->subject($subject); $listid = $info['listid']; $status = $info['status']; $sent = $info['sent']; $from_name = 'Trimart'; $from_address = '*****@*****.**'; $CI->email->from($from_address, $from_name); $query = "select email from sub_lists where listid =" . $listid; $conn = db_connect(); $result = $conn->query($query); if (!$result) { echo "No result"; return false; } else { if ($result->num_rows == 0) { echo "There is nobody subscribed to list number {$listid}"; return false; } } // include PEAR mail classes //include('Mail.php'); //include('Mail/Mime.php'); // instantiate MIME class and pass it the carriage return/line feed // character used on this system //$message = new Mail_mime("\r\n"); // read in the text version of the newsletter $textfilename = APPPATH . "archive\\" . $listid . "\\" . $mailid . "\\text.txt"; //$tfp = fopen($textfilename, "r"); //$text = fread($tfp, filesize($textfilename)); //fclose($tfp); // read in the HTML version of the newsletter $htmlfilename = APPPATH . "archive\\" . $listid . "\\" . $mailid . "\\index.html"; //$hfp = fopen($htmlfilename, "r"); //$html = fread($hfp, filesize($htmlfilename)); //fclose($hfp); // add HTML and text to the mimuser object //$message->setTXTBody($text); //$message->setHTMLBody($html); // get the list of images that relate to this message $query = "select path, mimetype from images where mailid = {$mailid}"; $result = $conn->query($query); if (!$result) { echo '<p>Unable to get image list from database.</p>'; return false; } $num = $result->num_rows; for ($i = 0; $i < $num; $i++) { //load each image from disk $row = $result->fetch_array(); $imgfilename = APPPATH . "archive\\{$listid}\\{$mailid}\\" . $row[0]; //var_dump($imgfilename); $imgtype = $row[1]; // add each image to the object //$message->addHTMLImage($imgfilename, $imgtype, $imgfilename, true); $CI->email->attach($imgfilename); } // create message body //$body = $message->get(); // create message headers $from = '"' . get_real_name($admin_user) . '" <' . $admin_user . '>'; $hdrarray = array('From' => $from, 'Subject' => $subject); //$hdrs = $message->headers($hdrarray); // create the actual sending object //$sender =& Mail::factory('mail'); if ($status == 'STORED') { // send the HTML message to the administrator //$sender->send($admin_user, $hdrs, $body); // send the plain text version of the message to administrator //mail($_POST['emailAddr'], $subject, $text, 'From: "'.$admin_user.'" <'.$admin_user.">"); //var_dump($_POST['emailAddr']); if (mail($_POST['emailAddr'], $subject, 'Hello')) { echo "<p>Success you genius</p>"; } $CI->email->to($_POST['emailAddr']); //var_dump($_POST['emailAddr']); if (mail($_POST['emailAddr'], $subject, 'Hello', $from_address)) { echo "Mail sent to {$admin_user} with email address " . $_POST['emailAddr']; // mark newsletter as tested $query = "update mail set status = 'TESTED' where mailid = {$mailid}"; $result = $conn->query($query); echo '<p>Press send again to send mail to whole list.<center>'; display_button('send', "&id={$mailid}"); echo '</center></p>'; } /*else { echo $CI->email->print_debugger(); }*/ } else { if ($status == 'TESTED') { //send to whole list $query = "select subscribers.realname, sub_lists.email, \n subscribers.mimetype \n from sub_lists, subscribers \n where listid = {$listid} and \n sub_lists.email = subscribers.email"; $result = $conn->query($query); if (!$result) { echo '<p>Error getting subscriber list</p>'; } $count = 0; // for each subscriber while ($subscriber = $result->fetch_row()) { if ($subscriber[2] == 'H') { //send HTML version to people who want it //$sender->send($subscriber[1], $hdrs, $body); $CI->email->send(); } else { //send text version to people who don't want HTML mail /*mail($subscriber[1], $subject, $text, 'From: "'.get_real_name($admin_user).'" <'.$admin_user.">");*/ $CI->email->to($subscriber[1]); $CI->email->send(); } $count++; } $query = "update mail set status = 'SENT', sent = now() \n where mailid = {$mailid}"; $result = $conn->query($query); echo "<p>A total of {$count} messages were sent.</p>"; } else { if ($status == 'SENT') { echo '<p>This mail has already been sent.</p>'; } } } }