PHPilliterate Posted January 6, 2008 Share Posted January 6, 2008 Howdy! I have zero php skill and need a wee bit of help. I am creating a mail page and would like to be able to send email to mulitiple recipients (sounds easy enough, right?) but the trick is I need to populate my list of potential TO: recipients from a database and include checkboxes beside each name....then I need to figure out how to have my mail loop through the checked names. I am using a Dreamweaver extension called UniversalEmail that I hoped would make things easier for me. I hope someone can help me (in basic NOOB terms) Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted January 6, 2008 Share Posted January 6, 2008 alright lets clean up a few things first 1) You don't have zero skills just not a lot 2) Do not use dreamweaver at all for scripting period use a text editor this is a good one Notepad++ 3) Do not send to multiple receipts via the "to" part as it remove their privacy use the BCC heaer 4) Show us some code for what you have built. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 7, 2008 Share Posted January 7, 2008 ok - im not goign to code it for you here - but this is the basics: loop through database records and make your table wiht checkboxes from the $_POST data or however you send the data - you need to check which fields are ticked ( boolean values if im not mistaken) - and then compile an array of emails from those checked boxes. **this is not he best way to do it - however for a small list this would work. larger lists youl have to look at other email sending functions - not just mail(); ** loop through the final array of people to send emails to. have a vairbale that stores the email - and if you want the names and things personalised for each email - it probably requires a mysql_query eariler in the script. simply use the mail() function to send a copy of that email for you. :> Good luck Quote Link to comment Share on other sites More sharing options...
Taorluath Posted January 7, 2008 Share Posted January 7, 2008 Wait, are you sure whoever is hosting your website lets you send mail? I know that a lot of hosting sites have disabled sending emails in PHP. Quote Link to comment Share on other sites More sharing options...
PHPilliterate Posted January 7, 2008 Author Share Posted January 7, 2008 Thanks for the numerous replies! OK...1)the reason I use Dreamweaver is ...as I previously mentioned...I have zero php skillz. LOL My host does allow the use of php mail() function (thank goodness) Here is the codeing that is generated when I use the Un!versalEmail software (three different files are created by the program): on my page (emailtest2) <?php require_once('../../Connections/alflregister.php'); ?> <?php mysql_select_db($database_alflregister, $alflregister); $query_Recordset1 = "SELECT * FROM contacts"; $Recordset1 = mysql_query($query_Recordset1, $alflregister) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <?php require_once("../../WA_Universal_Email/Mail_for_Linux_PHP.php"); ?> <?php require_once("../../WA_Universal_Email/MailFormatting_PHP.php"); ?> <?php if ((isset($_POST["Submit"]))) { //WA Universal Email object="Mail for Linux" //Send Loop Once Per Entry $RecipientEmail = "".$row_Recordset1['cell'] ."";include("../../WA_Universal_Email/WAUE_emailtest2_1.php"); //Send Mail All Entries if ("invalid.php"!="") { header("Location: invalid.php"); } } ?> // my html here <?php mysql_free_result($Recordset1); ?> mail_for_linux (generated by Un!v mail) <?php function WAUE_AddAttachment($mailObj,$attPath) { if ($attPath && $attPath != "") { $fileArr = explode("|WA|",$attPath); if (WAUE_isAttachment($fileArr[sizeof($fileArr)-1])) { switch (sizeof($fileArr)) { case 4: $mailObj->attachments[] = array($fileArr[0], $fileArr[1], $fileArr[2], $fileArr[3]); break; case 3: $mailObj->attachments[] = array("application/octet-stream", $fileArr[0], $fileArr[1], $fileArr[2]); break; case 2: $mailObj->attachments[] = array("application/octet-stream", "base64", $fileArr[0], $fileArr[1]); break; default: $mailObj->attachments[] = array("application/octet-stream", "base64", "", $fileArr[0]); } } } return $mailObj; } function WAUE_AddBCC($mailObj,$bccEmail) { if ($bccEmail != "") { $bccArray = WA_getEmailArray($bccEmail); for ($bcc=0; $bcc < sizeof($bccArray); $bcc++) { if (WAUE_isEmailAddress($bccArray[$bcc][1])) { $mailObj->bccrecip[] = array($bccArray[$bcc][1], $bccArray[$bcc][0]); } } } return $mailObj; } function WAUE_AddCC($mailObj,$ccEmail) { if ($ccEmail != "") { $ccArray = WA_getEmailArray($ccEmail); for ($cc=0; $cc<sizeof($ccArray); $cc++) { if (WAUE_isEmailAddress($ccArray[$cc][1])) { $mailObj->ccrecip[] = array($ccArray[$cc][1], $ccArray[$cc][0]); } } } return $mailObj; } function WAUE_AddRecipient($mailObj,$recEmail) { if ($recEmail != "") { $recArray = WA_getEmailArray($recEmail); for ($rec=0; $rec<sizeof($recArray); $rec++) { if (WAUE_isEmailAddress($recArray[$rec][1])) { $mailObj->recipients[] = array($recArray[$rec][1], $recArray[$rec][0]); } } } return $mailObj; } function WAUE_BodyFormat($mailObj,$bodyFormat) { $mailObj->BodyFormat = $bodyFormat; return $mailObj; } function WAUE_Definition($serverName,$serverPort,$retPath,$organization,$xMailer,$charSet) { $mailObj = new WA_MAILOBJ($serverName,$serverPort,$retPath,$organization,$xMailer,$charSet); return $mailObj; } class WA_MAILOBJ { var $SMTP; var $Port; var $ReturnPath; var $Organization; var $XMailer; var $CharSet; var $Importance; var $BodyFormat; var $attachments; var $recipients; var $ccrecip; var $bccrecip; function WA_MAILOBJ($serverName,$serverPort,$retPath,$organization,$xMailer,$charSet) { $this->SMTP = $serverName; $this->Port = $serverPort; $this->ReturnPath = $retPath; $this->Organization = $organization; $this->XMailer = $xMailer; $this->CharSet = $charSet; if ($serverName != "") ini_set("SMTP", $serverName); if ($serverPort != "") ini_set("smtp_port", $serverPort); $this->Importance = ""; $this->BodyFormat = ""; $this->attachments = array(); $this->recipients = array(); $this->ccrecip = array(); $this->bccrecip = array(); } } function WAUE_SendMail($mailObj,$mailAttachments,$mailBCC,$mailCC,$mailTo,$mailImportance,$mailFrom,$mailSubject,$mailBody) { if (strpos($mailTo,"@") < 0 || sizeof($mailObj->recipients) == 0) { return; } $fromArray = WA_getEmailArray($mailFrom); $mailTo2 = ""; $mailContent = ""; $mailHeader = ""; $mailFrom = $fromArray[0][1]; $lineEnd = "\n"; if ($fromArray[0][0] != "") { $mailFrom = $fromArray[0][0]." <".$fromArray[0][1].">"; } $mailHeader .= "MIME-Version: 1.0".$lineEnd; if (sizeof($mailObj->attachments) > 0 && is_array($mailObj->attachments[0])) { $mailHeader .= "Content-Type: multipart/mixed"; $mailHeader .= "; boundary=\"WAMULTIBREAKWA\"".$lineEnd; } else if ($mailObj->BodyFormat == 2) { $mailHeader .= "Content-Type: multipart/alternative"; $mailHeader .= "; boundary=\"WAMULTIBREAKWA\"".$lineEnd; $headers = ""; } else { if ($mailObj->BodyFormat == 1) $mailHeader .= "Content-Type: text/plain"; elseif ($mailObj->BodyFormat == 0) $mailHeader .= "Content-Type: text/html"; if ($mailObj->CharSet != "") $mailHeader .= preg_replace("/[\r\n]/", "", "; charset=\"".$mailObj->CharSet."\"").$lineEnd; else $mailHeader .= $lineEnd; } foreach ($mailObj->recipients AS $emailArr) { if ($mailTo != "") $mailTo .= ", "; if ($mailTo2 != "") $mailTo2 .= ", "; if ($emailArr[0] != "") $mailTo .= $emailArr[0]; if ($emailArr[1] != "") $mailTo2 .= $emailArr[1]." <".$emailArr[0].">"; else $mailTo2 .= $emailArr[0]; } if (strpos($mailTo2, "@")) { $mailTo = $mailTo2; } $mailHeader .= preg_replace("/[\r\n]/", "", "From: ".$mailFrom).$lineEnd; foreach ($mailObj->ccrecip AS $emailArr) { if ($mailCC != "") $mailCC .= ", "; if ($emailArr[1] != "") $mailCC .= $emailArr[1]." <".$emailArr[0].">"; else $mailCC .= $emailArr[0]; } if (strpos($mailCC, "@")) { $mailHeader .= preg_replace("/[\r\n]/", "", "Cc: ".$mailCC).$lineEnd; } foreach ($mailObj->bccrecip AS $emailArr) { if ($mailBCC != "") $mailBCC .= ", "; if ($emailArr[1] != "") $mailBCC .= $emailArr[1]." <".$emailArr[0].">"; else $mailBCC .= $emailArr[0]; } if (strpos($mailBCC, "@")) { $mailHeader .= preg_replace("/[\r\n]/", "", "Bcc: ".$mailBCC).$lineEnd; } $mailHeader .= preg_replace("/[\r\n]/", "", "Reply-To: ".$fromArray[0][1]).$lineEnd; $mailHeader .= preg_replace("/[\r\n]/", "", "X-Sender: ".$mailFrom).$lineEnd; $mailHeader .= preg_replace("/[\r\n]/", "", "X-Priority: ".$mailObj->Importance).$lineEnd; $mailHeader .= "Date: ". date('r (T)').$lineEnd; if ($mailObj->ReturnPath != "") { $retArray = WA_getEmailArray($mailObj->ReturnPath); $mailObj->ReturnPath = "<".$retArray[0][1].">"; if ($retArray[0][0] != "") { $mailObj->ReturnPath = $retArray[0][0]." <".$retArray[0][1].">"; } $mailHeader .= preg_replace("/[\r\n]/", "", "Return-Path: ".$mailObj->ReturnPath).$lineEnd; $theMSGID = $retArray[0][1]; $theMSGID = explode("@", $theMSGID); $theMSGID = "<".md5($theMSGID[0]).">@".$theMSGID[1]; $mailHeader .= preg_replace("/[\r\n]/", "", "Message-ID: ".$theMSGID).$lineEnd; } if ($mailObj->Organization != "") { $mailHeader .= preg_replace("/[\r\n]/", "", "Organization: ".$mailObj->Organization).$lineEnd; } if ($mailObj->XMailer != "") { $mailHeader .= preg_replace("/[\r\n]/", "", "X-Mailer: ".$mailObj->XMailer).$lineEnd; } if ($mailObj->BodyFormat == 2 || sizeof($mailObj->attachments) > 0) { $mailContent = $lineEnd."--WAMULTIBREAKWA".$lineEnd; switch ($mailObj->BodyFormat) { case 2: $splitBreak = "--WAMULTIBREAKWA"; if (sizeof($mailObj->attachments) > 0) { $mailContent .= "Content-Type: multipart/alternative; boundary=\"WAATTBREAKWA\"".$lineEnd.$lineEnd."--WAATTBREAKWA".$lineEnd; $splitBreak = "--WAATTBREAKWA"; } $mailContent .= "Content-Type: text/plain"; if ($mailObj->CharSet != "") $mailContent .= preg_replace("/[\r\n]/", "", "; charset=\"".$mailObj->CharSet."\"").$lineEnd; else $mailContent .= $lineEnd; $theReplace = $lineEnd.$splitBreak.$lineEnd; $theReplace .= "Content-Type: text/html"; if ($mailObj->CharSet != "") $theReplace .= "; charset=\"".$mailObj->CharSet."\"".$lineEnd.$lineEnd; else $theReplace .= $lineEnd.$lineEnd; $mailBody = str_replace("<multipartbreak>", $theReplace, $mailBody); $mailContent .= $lineEnd.$mailBody; $mailContent .= $lineEnd.$splitBreak."--".$lineEnd; break; case 1: $mailContent .= "Content-Type: text/plain"; if ($mailObj->CharSet != "") $mailContent .= preg_replace("/[\r\n]/", "", "; charset=\"".$mailObj->CharSet."\"").$lineEnd; else $mailContent .= $lineEnd; $mailContent .= "Content-Transfer-Encoding: 8bit".$lineEnd; $mailContent .= $lineEnd.$mailBody; break; case 0: $mailContent .= "Content-Type: text/html"; if ($mailObj->CharSet != "") $mailContent .= preg_replace("/[\r\n]/", "", "; charset=\"".$mailObj->CharSet."\""); $mailContent .= $lineEnd; $mailContent .= "Content-Transfer-Encoding: 8bit".$lineEnd; $mailContent .= $lineEnd.$mailBody; break; } } else { $mailContent .= $mailBody; } if(sizeof($mailObj->attachments) > 0) { foreach ($mailObj->attachments as $fileArr) { if (is_readable($fileArr[3])) { if (strtolower($fileArr[1]) == "base64") { $data = chunk_split(base64_encode(implode("", file($fileArr[3])))); } else { $data = implode("", file($fileArr[3])); } $mailAttachments .= $lineEnd."--WAMULTIBREAKWA"; $mailAttachments .= $lineEnd."Content-Type: ".$fileArr[0]; $mailAttachments .= "; name=\"".basename($fileArr[3])."\"".$lineEnd; $mailAttachments .= "Content-Transfer-Encoding: ".$fileArr[1].$lineEnd; $mailAttachments .= "Content-Disposition: inline;"; $mailAttachments .= " filename=\"".basename($fileArr[3])."\"".$lineEnd.$lineEnd; $mailAttachments .= $data; } } } $mailContent = str_replace("<multipartbreak>", "--WAMULTIBREAKWA".$lineEnd, $mailContent); $mailHeader = str_replace("<multipartbreak>", "--WAMULTIBREAKWA".$lineEnd, $mailHeader); if(sizeof($mailObj->attachments) > 0 && $mailObj->BodyFormat==2) { $mailContent = $mailAttachments.$mailContent.$lineEnd."--WAMULTIBREAKWA--"; } else { $mailContent = $mailContent.$mailAttachments; } $mailObj = mail($mailTo,$mailSubject,$mailContent,$mailHeader); return $mailObj; } function WAUE_SetImportance($mailObj,$Importance) { $newPriority = 3; if (!is_numeric($Importance)) { if (strtoupper($Importance) == "HIGH") { $newPriority = 1; } if (strtoupper($Importance) == "LOW") { $newPriority = 5; } } else { $newPriority = $Importance; } $mailObj->Importance = $newPriority; return $mailObj; } ?> mail_formatting (Un!v. mail) <?php function WAUE_isAttachment($attPath) { if ($attPath && $attPath != "" && strpos($attPath, ".") > 0) { return true; } return false; } function WAUE_isEmailAddress($testAddress) { $isValidEmail = true; if (strpos($testAddress, ";") !== false) { $testAddress = substr($testAddress, 0, strpos($testAddress, ";")); } if (strpos($testAddress, ",") !== false) { $testAddress = substr($testAddress, 0, strpos($testAddress, ",")); } if (strpos($testAddress, "<") !== false && strpos($testAddress, "<") < strpos($testAddress, "@")) { $testAddress = substr($testAddress, strpos($testAddress, "<")+1); if (strpos($testAddress, ">") !== false && strpos($testAddress, ">") > strpos($testAddress, "@")) { $testAddress = substr($testAddress, 0, strpos($testAddress, ">")); } } if ($testAddress != "") { $knownDomsPat = "/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/"; $emailPat = "/^(.+)@(.+)$/"; $accepted = "[^\s\(\)><@,;:\\\"\.\[\]]+"; $quotedUser = "(\"[^\"]*\")"; $ipDomainPat = "/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/"; $section = "(".$accepted."|".$quotedUser.")"; $userPat = "/^".$section."(\\.".$section.")*$/"; $domainPat = "/^".$accepted."(\\.".$accepted.")*$/"; $theMatch = preg_match($emailPat,$testAddress,$MatchVal); $acceptedPat = "/^" . $accepted . "$/"; $userName = ""; $domainName = ""; if (!$theMatch) { $isValidEmail = false; } else { $userName = $MatchVal[1]; $domainName = $MatchVal[2]; $domArr = split("\.",$domainName); $IPArray = preg_match($ipDomainPat,$domainName,$ipMatch); for ($x=0; $x < strlen($userName); $x++) { if ((ord(substr($userName,$x,1)) > 127 && ord(substr($userName,$x,1)) < 192) || ord(substr($userName,$x,1)) > 255) { $isValidEmail = false; } } for ($x=0; $x < strlen($domainName); $x++) { if ((ord(substr($domainName,$x,1)) > 127 && ord(substr($domainName,$x,1)) < 192) || ord(substr($domainName,$x,1)) > 255) { $isValidEmail = false; } } if (!preg_match($userPat,$userName)) { $isValidEmail = false; } if ($IPArray) { for ($x=1; $x <= 4; $x++) { if ($IPArray[x] > 255) { $isValidEmail = false; } } } for ($x=0; $x<sizeof($domArr); $x++) { if (!preg_match($acceptedPat,$domArr[$x]) || strlen($domArr[$x]) == 0 || (strlen($domArr[$x]) < 2 && $x >= sizeof($domArr)-2)) { $isValidEmail = false; } } if (strlen($domArr[count($domArr)-1]) !=2 && !preg_match($knownDomsPat,$domArr[count($domArr)-1])) { $isValidEmail = false; } if (count($domArr) < 2) { $isValidEmail = false; } } } return $isValidEmail; } function WA_getEmailArray($emailStr) { $retArray = array(); $emailArr = explode(";",$emailStr); foreach ($emailArr AS $emailString) { if (strpos($emailString,"@") > 0) { $emailArr2 = explode("|WA|", $emailString); if (sizeof($emailArr2) == 1) { $tempArray = array(2); $tempArray[0] = ""; $tempArray[1] = WA_StripSpaces($emailString); $retArray[] = $tempArray; } else { $tempArr = array("", ""); $eArr0 = $emailArr2[0]; $eArr1 = $emailArr2[1]; if (strpos($eArr1, "@") !== false) { $tempArr[0] = WA_StripSpaces($emailArr2[0]); $tempArr[1] = WA_StripSpaces($emailArr2[1]); } else { $tempArr[0] = WA_StripSpaces($emailArr2[1]); $tempArr[1] = WA_StripSpaces($emailArr2[0]); } $retArray[] = $tempArr; } } } return $retArray; } function WA_FormatColumn($align,$numspaces,$content) { $WA_FormatColumn_return = ""; $numspaces = intval($numspaces); if (strlen($content) > $numspaces) { $WA_FormatColumn_return = substr($content,0,$numspaces); } else { switch (strtolower($align)) { case "right": $WA_FormatColumn_return = WA_RightAlign($numspaces,$content); break; case "left": $WA_FormatColumn_return = WA_LeftAlign($numspaces,$content); break; } if (strtolower($align) == "center") { $WA_FormatColumn_return = WA_CenterAlign($numspaces,$content); } } return $WA_FormatColumn_return; } function WA_RightAlign($numspaces, $content) { $WA_RightAlign_return = $content; while (strlen($WA_RightAlign_return) < $numspaces) { $WA_RightAlign_return = " ".$WA_RightAlign_return; } return $WA_RightAlign_return; } function WA_LeftAlign($numspaces, $content) { $WA_LeftAlign_return = $content; while (strlen($WA_LeftAlign_return) < $numspaces) { $WA_LeftAlign_return = $WA_LeftAlign_return." "; } return $WA_LeftAlign_return; } function WA_CenterAlign($numspaces, $content) { $WA_CenterAlign_return = $content; for ($n=strlen($content); $n<$numspaces; $n++) { if (($n%2) == 1) { $WA_CenterAlign_return = $WA_CenterAlign_return." "; } else { $WA_CenterAlign_return = " ".$WA_CenterAlign_return; } } return $WA_CenterAlign_return; } function WA_StripSpaces($inStr) { $outStr = $inStr; $firstchar = substr($outStr, 0, 1); while ($firstchar == " ") { $outStr = substr($outStr,1); $firstchar = substr($outStr, 0, 1); } $firstchar = substr($outStr, strlen($outStr)-1, 1); while ($firstchar == " ") { $outStr = substr($outStr, 0, strlen($outStr)-1); $firstchar = substr($outStr, strlen($outStr)-1, 1); } return $outStr; } function WA_TrimLeadingSpaces($inStr) { $outStr = $inStr; $firstchar = substr($outStr, 0, 1); while ($firstchar == " ") { $outStr = substr($outStr,1); $firstchar = substr($outStr, 0, 1); } $firstchar = substr($outStr, strlen($outStr)-1, 1); while ($firstchar == " ") { $outStr = substr($outStr, 0, strlen($outStr)-1); $firstchar = substr($outStr, strlen($outStr)-1, 1); } return $outStr; } ?> and lastly WAUE_emailtest2_1 (Un!v. mail) <?php $MailAttachments = ""; $MailBCC = ""; $MailCC = ""; $MailTo = ""; $MailBodyFormat = ""; $MailBody = ""; $MailImportance = ""; $MailFrom = "".((isset($_POST["name"]))?$_POST["name"]:"") ."|WA|".((isset($_POST["email"]))?$_POST["email"]:"") .""; $MailSubject = "Gameday Notice:"; $_SERVER["QUERY_STRING"] = ""; //Global Variables $WA_MailObject = WAUE_Definition("relay-hosting.secureserver.net ","25","","","",""); if ($RecipientEmail) { $WA_MailObject = WAUE_AddRecipient($WA_MailObject,$RecipientEmail); } else { //To Entries } //Attachment Entries //BCC Entries //CC Entries //Body Format $WA_MailObject = WAUE_BodyFormat($WA_MailObject,0); //Set Importance $WA_MailObject = WAUE_SetImportance($WA_MailObject,"3"); //Start Mail Body //End Mail Body $WA_MailObject = WAUE_SendMail($WA_MailObject,$MailAttachments,$MailBCC,$MailCC,$MailTo,$MailImportance,$MailFrom,$MailSubject,$MailBody); $WA_MailObject = null; ?> If anyone can help me make heads or tails out of this, I'm all ears!! Quote Link to comment Share on other sites More sharing options...
PHPilliterate Posted January 10, 2008 Author Share Posted January 10, 2008 no takers?! Quote Link to comment 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.