Code to send Email using FCKEditor

mdemaree99

#1
Code to send out html email using front end with FCKEditor

Contains some ugly code since I am pulling email addreses from access database, but tried to put comments in so you could use a mysql db.

Issues for now.
1)  When I post internal link from website it shows up at a droplet.
     Internal links look like this:     http://[wblink29]

     Solution:  Send all links as external link.
     Internal links will show up normal.  http://www.yourwebsite.com/index.php

I didn't think about security of form since user must be registered and an admin to use the page.
Any security or ideas let me now and i'll incorportate it.

Downside is that this does not save a list of emails that have previously been sent.
However easier to manipulate than the other mass email programs.



$bccquery ="";
//initialize the to field for email
$toinitial ="sendto@email.com";

//connect to database (this used for MS Access Database
$conn = new COM('ADODB.Connection') or die('Could not make conn');
$rs = new COM('ADODB.Recordset') or die('Coult not make rs');
$connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=mydb.mdb";
$conn->Open($connstring);

//Connect to WebsiteBaker db
//My best guess at websitbaker query
//$query = "SELECT email FROM ".TABLE_PREFIX."users WHERE group_id <> 0";
//$result = $database->query($query);


// Select your email addresses in a search
$sql = "SELECT [E-MAIL], ClassCode FROM tblMembership
      Where ClassCode IN (1, 2, 3,4,5)
      AND [E-Mail] <> ''
      ";


//More access db
$rs->Open($sql, $conn, 1, 3);

while(!$rs->EOF) {

//$bccquery = $bccquery .$rs->Fields['E-Mail']->Value . "," ;

   $rs->MoveNext();
}

//Close access database
$rs->Close();

$conn->Close();

$rs=null;
$conn=null;



// now lets send the email.
//retrieves data from form
$to = $_POST['toemail'];
   
//Retrieves Subject of Email from Form
$subject = $_POST['subject'];
     
       
//$email = $_POST['email'] ;
//change this to your email.
   $to = $_POST['toemail'];
   $from = 'mdemaree99@yahoo.com' ;

//begin of HTML message
$message = $_POST['message'] ;
$message = stripslashes($message);


//change this to JLA email.
   $to = $_POST['toemail'] ;
   
//Sets who email is from  
   $from = "mdemaree99@yahoo.com";
 
//Header field for email  (need from to detrmine header)
   $headers  = "From: $from\r\n";
   $headers .= "Content-type: text/html\r\n";
 

//options to send to cc
  $ccemail = $_POST['ccemail'] ;
   if ($ccemail<>'')
  { $headers .= "Cc: $ccemail\r\n"; }
   
//options to send bcc
  $bccemail = $_POST['bccemail'] ;
  if ($bccemail<>'')
  {$headers .= "Bcc: $bccemail\r\n"; }

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form


// FORM to input data for email
//Predefines fields for the form
$toemail = 'mdemaree99@yahoo.com';
$ccemail = '';
$bccemail = $bccquery;



echo (" <form method='post' action=$PHP_SELF>  ");
echo ("<table>");

//TO
echo (" <tr><td valign='top'>TO:</td>");
echo (" <td><textarea name='toemail' type='text' rows='1' cols='50'>$toemail</textarea></td></tr>");

//CC
echo (" <tr><td valign='top'>CC:</td>");
echo ("<td> <textarea name='ccemail' type='text' rows='1' cols='50'>$ccemail</textarea></td></tr>");

//BCC
echo (" <tr><td valign='top'>   BCC:     </td> ");
echo ("<td> <textarea name='bccemail' type='text' rows='4' cols='50' />$bccemail</textarea></td></tr>");

//SUBJECT
echo (" <tr><td valign='top'>   SUBJECT: </td> ");
echo (" <td> <textarea name='subject' type='text' rows='1' cols='50' /></textarea></td></tr>  ");

//BODY OF EMAIL
ECHO (" <TR><td>Body:</td><TD> ");
ECHO ('  <input type="hidden" name="bd937a97e1a1514d" value="e1a1514d74ca5783" title="" alt="" />  ');

//Must modify to your website --see note below
ECHO ('  <input type="hidden" id="message" name="message" value="" style="display:none"/><input type="hidden" id="message___Config" value="CustomConfigurationsPath=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fckconfig.js&amp;EditorAreaCSS=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fckeditorarea.css&amp;StylesXmlPath=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fckstyles.xml&amp;TemplatesXmlPath=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fcktemplates.xml&amp;LinkBrowserURL=http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/browser/default/browser.html?Connector%3Dhttp://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php&amp;ImageBrowserURL=http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/browser/default/browser.html?Connector%3Dhttp://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php&amp;FlashBrowserURL=http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/browser/default/browser.html?Connector%3Dhttp://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php" style="display:none" /><iframe id="message___Frame" src="http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/fckeditor.html?InstanceName=message&amp;Toolbar=WBToolbar" width="100%" height="350" frameborder="0" scrolling="no"></iframe>  ');
ECHO ("  </TD></TR> ");

//Must modify to your website
// Create a page in WebsiteBaker with WYSIWYG section
// right click to view source and copy FCKEditor settings.
// replace all content64 with item you are pulling from post  (previous is message)
//ECHO ('  <input type="hidden" name="bd937a97e1a1514d" value="e1a1514d74ca5783" title="" alt="" />  ');
//ECHO ('  <input type="hidden" id="content64" name="content64" value="" style="display:none" /><input type="hidden" id="content64___Config" value="CustomConfigurationsPath=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fckconfig.js&amp;EditorAreaCSS=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fckeditorarea.css&amp;StylesXmlPath=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fckstyles.xml&amp;TemplatesXmlPath=http://www.jlarlington.org/jlabaker/modules/fckeditor/wb_config/wb_fcktemplates.xml&amp;LinkBrowserURL=http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/browser/default/browser.html?Connector%3Dhttp://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php&amp;ImageBrowserURL=http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/browser/default/browser.html?Connector%3Dhttp://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php&amp;FlashBrowserURL=http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/browser/default/browser.html?Connector%3Dhttp://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php" style="display:none" /><iframe id="content64___Frame" src="http://www.jlarlington.org/jlabaker/modules/fckeditor/fckeditor/editor/fckeditor.html?InstanceName=content64&amp;Toolbar=WBToolbar" width="100%" height="350" frameborder="0" scrolling="no"></iframe>  ');

 
echo (" <tr><td colspan='2' style='text-align: center;'> <input type='submit' value='Send Email' name='submit'></td></tr> ");
echo ("  </table>  ");  
echo (" </form>");


//Send email once email is complete and Send Email clicked

} else {
     
 
   // now lets send the email.
   
         if (mail($to, $subject, $message, $headers))
             {    
                 //this will give user a view on what email will look like        
                     echo "Message has been sent....!";    
                     echo "Message has been sent....!<br><br>";  
                     echo ("From: $from <br> ");
                     echo ("TO: $to <br> ");
                     echo ("CC:  $ccemail <br>");
                     echo ("BCC: $bccemail <br>");
                     echo ("Subject: $subject <br><BR>");
                     echo ("Body: <br> $message ");
                   }
            else {            
                   echo 'There was a problem sending the email.';          
                  }
             
}