Jump to content

[SOLVED] Help with using selections and emailing


GreenSmurf

Recommended Posts

I have my index.php page listed here. Now the area I want to focus on is being able to select peoples and mass send an e-mail. Preferably just send a list of names and e-mail addresses to another page to interpret and allow the user to send the e-mails.

 

I suppose that what I am looking for is an easy way to pull the information and send it through a submition button.

<?
 include ("include/dbconnect.php");
 include ("include/format.inc.php");
 ?><title>Address book <? echo ($group_name != "" ? "($group_name)":""); ?></title><?
 include ("include/header.inc.php");
?>
 <br><br>
<center>
 <table border="0" cellspacing="2">
 <form method="POST" action="<? $PHP_SELF ?>">
   <tr valign=center>
  <td valign="top"> 
       <input type="text" value="<? echo $searchstring; ?>" name="searchstring" title="Search for any text" size="45"/>
       <input type="submit" value="Search"></td>
   <td> </td></tr>
   
 </form>

<script type="text/javascript">
function MassSelection()
{
 for (i = 0; i < document.getElementsByName("selected[]").length; i++)
 {
    document.getElementsByName("selected[]")[i].checked = document.getElementById("MassCB").checked;
 }

 // location.href = "mailto:"+addresses;

}


function MailSelection()
{

 var addresses = "";
 var dst_count = 0;

 for (i = 0; i < document.getElementsByName("selected[]").length; i++)
 {
     if( document.getElementsByName("selected[]")[i].checked == true)
     {
        if( document.getElementsByName("selected[]")[i].accept != "")
        {
           addresses = addresses + ";" + document.getElementsByName("selected[]")[i].accept;
           dst_count++;
        }
     }
 }

 if(dst_count == 0)
   alert("No address selected.");
 else
   location.href = "mailto:"+addresses;
}
</script>
<!--
<table width=100%><td valign=top style="border-top-width:2.5px;border-top-style:solid;border-top-color:#FFFFFF">
-->
<tr><td>
<?
 $page_name="index.php"; // If you use this code with a different page ( or file ) name then change this
 if(!($start > 0)) { // This variable is set to zero for the first page
   $start = 0;
 }
 $eu = ($start - 0);
 $limit = 35; // No of records to be shown per page.
 $this2 = $eu + $limit;
 $back = $eu - $limit;
 $next = $eu + $limit;
//$grp = $_REQUEST["group"];
/*$sql="SELECT group_name FROM $table_groups ORDER BY lower(group_name) ASC";
$result_groups = mysql_query($sql);
$myrow = mysql_fetch_array($result_groups);*/
/*if ($grp == '' OR $grp == NULL){

  $grpDis = '';

}
else {

    $grpDis = 'group='.$grp.'&';
    //./?group=$group_name'

} */
$alpha = $_REQUEST["alphabet"];
//Alpha Check
if ($alpha != NULL OR $alpha != '')
  $alpha='alphabet='.$_REQUEST["alphabet"].'&';
//Group Check
if ($group_name != ""){
  $grp=ereg_replace(" ",'+',$group_name);
  $grpdis='group='.$grp.'&';
}
//Search Check
if ($searchstring != ""){
 $search='searchstring='.$searchstring."&";
}
if ($_REQUEST["sort"]!= ''){
 $pSort = 'sort='.$_REQUEST["sort"].'&';
}
if ($_REQUEST["order"]!= ''){
 $pOrder = 'order='.$_REQUEST["order"].'&';
}
$link = "index${page_ext_qry}".$search.$stDis."alphabet";
$link2 = "index${page_ext_qry}".$alpha.$search.$stDis;
//echo $start."||".$_REQUEST["start"]."<br><br>";
echo "<a style='font-size:85%' href='$link=a'>A</a> | <a style='font-size:85%' href='$link=b'>B</a> |
        <a style='font-size:85%' href='$link=c'>C</a> | <a style='font-size:85%' href='$link=d'>D</a> |
        <a style='font-size:85%' href='$link=e'>E</a> | <a style='font-size:85%' href='$link=f'>F</a> |
        <a style='font-size:85%' href='$link=g'>G</a> | <a style='font-size:85%' href='$link=h'>H</a> |
        <a style='font-size:85%' href='$link=i'>I</a> | <a style='font-size:85%' href='$link=j'>J</a> |
        <a style='font-size:85%' href='$link=k'>K</a> | <a style='font-size:85%' href='$link=l'>L</a> |
        <a style='font-size:85%' href='$link=m'>M</a> | <a style='font-size:85%' href='$link=n'>N</a> |
        <a style='font-size:85%' href='$link=o'>O</a> | <a style='font-size:85%' href='$link=p'>P</a> |
        <a style='font-size:85%' href='$link=q'>Q</a> | <a style='font-size:85%' href='$link=r'>R</a> |
        <a style='font-size:85%' href='$link=s'>S</a> | <a style='font-size:85%' href='$link=t'>T</a> |
        <a style='font-size:85%' href='$link=u'>U</a> | <a style='font-size:85%' href='$link=v'>V</a> |
        <a style='font-size:85%' href='$link=w'>W</a> | <a style='font-size:85%' href='$link=x'>X</a> |
        <a style='font-size:85%' href='$link=y'>Y</a> | <a style='font-size:85%' href='$link=z'>Z</a> |
        <a style='font-size:85%' href='".($group == '' || $group == '[none]' || $fixgroup ? "$link=''" : '?group='.$group)."'>All</a>";
?>
</td>
</table>
</center>
<br>
<hr>
<?

//Shorten String Function Just like it sounds
function ShortenText($text) {

       // Change to the number of characters you want to display
       $chars = 20;

       $text = $text." ";
       $text = substr($text,0,$chars);
       $text = substr($text,0,strrpos($text,' '));
       $text = $text."...";

       return $text;

   }
//End Function
//Phone Function
function phone_number($sPhone)
{
 $sPhone = ereg_replace("[^0-9]",'',$sPhone);

 if(strlen($sPhone) != 10) return(False);
   $sArea = substr($sPhone,0,3);

 $sPrefix = substr($sPhone,3,3);
 $sNumber = substr($sPhone,6,4);
 $sPhone = "(".$sArea.")".$sPrefix."-".$sNumber;

 return($sPhone);
}
//End Function
//
//SORT!!!
//
$rSort = $_REQUEST["sort"];
if ($searchstring!="" AND $rSort==""){

$rsort = 'lastname, firstname, boss, lastname2, firstname2, clientID';

}
$rOrder = $_REQUEST["order"];
if ($rOrder == '' OR $rOrder=='ASC'){

  $rOrder = 'DESC';

}
else {

    $rOrder = 'ASC';

}

if ($rOrder!='' AND $rSort!='') {

  $sort = 'ORDER BY '.$rSort.' '.$rOrder;

}
else {

    $sort = 'ORDER BY lastname, firstname, boss';

}
//End Sort!
//

if ($searchstring AND $alphabet)
{

$sql="SELECT * FROM $base_from_where AND LEFT(lastname,1) = '$alphabet'
                 AND (lastname  LIKE '%$searchstring%'
                 OR firstname LIKE '%$searchstring%' 
                 OR lastname2 LIKE '%$searchstring%'
                 OR firstname2 LIKE '%$searchstring%'
                 OR address   LIKE '%$searchstring%' 
		OR boss	 LIKE '%$searchstring%'
		OR clientID  LIKE '%$searchstring%'
		OR accnt  LIKE '%$searchstring%'
		OR salesrep  LIKE '%$searchstring%'
                 OR email     LIKE '%$searchstring%')
             ".$sort." LIMIT $eu, $limit;";
 $query2="SELECT * FROM $base_from_where AND LEFT(lastname,1) = '$alphabet'
                 AND (lastname  LIKE '%$searchstring%'
                 OR firstname LIKE '%$searchstring%'
                 OR lastname2 LIKE '%$searchstring%'
                 OR firstname2 LIKE '%$searchstring%'
                 OR address   LIKE '%$searchstring%'
		OR boss	 LIKE '%$searchstring%'
		OR clientID  LIKE '%$searchstring%'
		OR accnt  LIKE '%$searchstring%'
		OR salesrep  LIKE '%$searchstring%'
                 OR email     LIKE '%$searchstring%')
             ".$sort.";";
 $result2=mysql_query($query2);
 $nume=mysql_num_rows($result2);
}
else if ($searchstring)
{

$sql="SELECT * FROM $base_from_where AND (lastname  LIKE '%$searchstring%'
                 OR firstname LIKE '%$searchstring%'
                 OR lastname2 LIKE '%$searchstring%'
                 OR firstname2 LIKE '%$searchstring%'
                 OR address   LIKE '%$searchstring%'
		OR boss	 LIKE '%$searchstring%'
		OR clientID  LIKE '%$searchstring%'
		OR accnt  LIKE '%$searchstring%'
		OR salesrep  LIKE '%$searchstring%'
                 OR email     LIKE '%$searchstring%')
             ".$sort." LIMIT $eu, $limit;";
  $query2="SELECT * FROM $base_from_where AND (lastname  LIKE '%$searchstring%'
                 OR firstname LIKE '%$searchstring%'
                 OR lastname2 LIKE '%$searchstring%'
                 OR firstname2 LIKE '%$searchstring%'
                 OR address   LIKE '%$searchstring%'
		OR boss	 LIKE '%$searchstring%'
		OR clientID  LIKE '%$searchstring%'
		OR accnt  LIKE '%$searchstring%'
		OR salesrep  LIKE '%$searchstring%'
                 OR email     LIKE '%$searchstring%')
             ".$sort.";";
 $result2=mysql_query($query2);
 $nume=mysql_num_rows($result2);
}
else if ($alphabet)
{
       $sql = "SELECT * FROM $base_from_where AND LEFT(lastname,1) = '$alphabet' ".$sort." LIMIT $eu, $limit;";
       $query2="SELECT * FROM $base_from_where AND LEFT(lastname,1) = '$alphabet' ".$sort.";";
       $result2=mysql_query($query2);
       $nume=mysql_num_rows($result2);
}
else
{
       $sql="SELECT * FROM $base_from_where ".$sort." LIMIT $eu, $limit;";
       $query2="SELECT * FROM $base_from_where ".$sort.";";
       $result2=mysql_query($query2);
       $nume=mysql_num_rows($result2);
}
$result = mysql_query($sql);
$resultsnumber = mysql_numrows($result);

echo "<TABLE BORDER=0 width=100%>";
echo "<td><strong>Number of results: $nume</td>";

if(isset($table_groups) and $table_groups != "" and !$is_fix_group)
{
?>
<td align=right>
<form>
<select name="group" onChange="this.parentNode.submit()">
<?
if($group_name != "") 
{
	echo "<option>$group_name</option>\n";
}
?>
<option value="">[all]</option>
<option value="[none]">[none]</option>
<?
$sql="SELECT group_name FROM $table_groups ORDER BY lower(group_name) ASC";
$result_groups = mysql_query($sql);
$result_gropup_snumber = mysql_numrows($result_groups);

while ($myrow = mysql_fetch_array($result_groups))
{
	echo "<option>".$myrow["group_name"]."</option>\n";
}
?>
</select>
</form>
</td></tr>
</table>
<?
}
?>
<form name=MainForm method="POST" action="group<? echo $page_ext; ?>">
<input type="hidden" name="group" value="<? echo $group; ?>">
<table border=0 cellpadding="6" align="center">
<col width=1*>
<col width=2*>
<col width=3*>
<col width=4*>
<col width=1>
<col width=150>
<col width=84>
<col width=16>
<col width=16>
<col width=16>
<col width=16>
<col width=16>
<col width=6*>
<tr padding="0" align="center">
             <td> </td>
             <td><u><a href=<?php echo $link2 ?>sort=clientID&order=<?php echo $rOrder ?>>Client ID</a></u></td>
             <td><u><a href=<?php echo $link2 ?>sort=lastname&order=<?php echo $rOrder ?>>Lastname</a></u></td>
             <td><u><a href=<?php echo $link2 ?>sort=firstname&order=<?php echo $rOrder ?>>Firstname</a></u></td>
             <td><u><a href=<?php echo $link2 ?>sort=boss&order=<?php echo $rOrder ?>>Company</a></u></td>
             <td><u><a href=<?php echo $link2 ?>sort=email&order=<?php echo $rOrder ?>>E-mail</a></u></td>
             <td><u>Phone #</u></td>
             <td> </td>
             <td> </td>
             <td> </td>
             <td> </td>
             <td> </td>
             <td><u><a href=<?php echo $link2 ?>sort=accnt&order=<?php echo $rOrder ?>>Accountant</a></u></td>
             <td><u>Activity</u></td>
</tr>
<?
$alternate = "2"; 

include ("guess.inc");

while ($myrow = mysql_fetch_array($result))
{

	$clientID = $myrow["clientID"];
	$firstname = $myrow["firstname"];
	$id = $myrow["id"];
	$lastname = $myrow["lastname"];
	$boss = $myrow["boss"];

	$email  = ($myrow["email"] != "" ? $myrow["email"] : ($myrow["email2"] != "" ? $myrow["email2"] : ""));
	$email2 = $myrow["email2"];

	$home   = $myrow["home"];
	$mobile = $myrow["mobile"];
	$work   = $myrow["work"];
	$accnt  = $myrow["accnt"];
	$notes  = $myrow["notes"];

	// Phone order home->mobile->work
	$phone = ($myrow["home"] != "" ? $myrow["home"]
                                              : ($myrow["mobile"] != "" ? $myrow["mobile"]
                                                                        : $myrow["work"]));
	/*$phone = str_replace("'", "",
                        str_replace('/', "", 
                        str_replace(" ", "", 
                        str_replace(".", "", $phone))));*/
                        
       $phone = phone_number($phone);

	if ($alternate == "1") { 
		$color = "#ffffff"; 
		$alternate = "2"; 
	} 
	else { 
		$color = "#efefef"; 
		$alternate = "1"; 
	}
	echo "<TR bgcolor=$color>";
	echo "<TD><input type=checkbox id=".$id." name='selected[]' value='$id' title='Select ($firstname $lastname)' alt='Select ($firstname $lastname)' accept=".$myrow['email'].";".$myrow['email2']."></td>";
	echo "<td>$clientID</td>";
	echo "<TD>$lastname</td>";
	echo "<td>$firstname</td>";
	echo "<td>".ShortenText($boss)."</td>";
	echo "<td><a href='mailto:$email'>$email</a></td>";
	echo "<td align=right>$phone</td>";
	echo "<td><a href='view${page_ext_qry}id=$id'><img border=0 src=icons/status_online.png   width=16 height=16 title='Details' alt='Details'/></a></td>";
               if(! $read_only)
	  echo "<td><a href='edit${page_ext_qry}id=$id'><img border=0 src=icons/pencil.png width=16 height=16 title='Edit' alt='Edit'/></a></td>";
	echo "<td><font size=-2><a href='vcard${page_ext_qry}id=$id'><img border=0 src=icons/vcard.png   width=16 height=16 title='vCard' alt='vCard'/></a></font></td>";

               if( substr($phone, 0, 1) == "0" || substr($phone, 0, 3) == "+41")
	{
		$country = "Switzerland";
	}
	else 	$country = "";

	if($map_guess)
	{
	if($myrow["address"] != "")
	echo "<td><font size=-2><a href='http://maps.google.com/maps?q=".urlencode(trim(str_replace("\r\n", ", ", $myrow["address"]))." ".trim($myrow["city"]).", ".trim($myrow["state"])." ".trim($myrow["zip"]).", $country")."&t=h' target='_blank'>
                         <img border=0 src=icons/car.png width=16 height=16 title='Google Maps' alt='vCard'/></a></font></td>";
	else echo "<td/>";
	}

	$homepage = guessHomepage($email, $email2);
	if(strlen($homepage) > 0)
	{
		echo "<td><font size=-2><a href='http://$homepage' target='_blank'><img border=0 src=icons/house.png   width=16 height=16 title='Guessed Homepage ($homepage)' alt='Guessed Homepage ($homepage)'/></a></font></td>";
	} else
		echo "<td/>";
       echo "<td><a href=\"javascript:popImage('$accnt.jpg','$accnt')\">$accnt</a></td>";
       echo "<td>".ShortenText($notes)."</td>";
	echo "</TR>\n";
}

echo "<tr height=2/>";
echo "<TR >";
	echo "<TD><input type=checkbox id=MassCB onclick=\"MassSelection()\"></td><td><em><strong>Select all</strong></em></TD>";
echo "</TR>\n";
echo "<tr height=9/>";
echo "</TR></TABLE>";
 echo "<TABLE width=100%><TR>";
       echo "<td><input type=button value=\"Send e-Mail\" onclick=\"MailSelection()\"/></td>";

if(isset($table_groups) and $table_groups != "" and !$is_fix_group)
{

	// -- Remove from group --
	if($group_name != "" and $group_name != "[none]") 
	{
        	echo "<td align=center><input type=submit name=remove value='Remove from \"$group_name\"'/></td>";
	} else
        	echo "<td align=center/>";

	// -- Add to a group --
       	echo "<td align=right><input type=submit name=add value='Add to group'/>-";
       	echo "<select name=to_group>";

	$sql="SELECT group_name FROM $table_groups ORDER BY lower(group_name) ASC";
	$result = mysql_query($sql);
	$resultsnumber = mysql_numrows($result);

	while ($myrow = mysql_fetch_array($result))
	{
		echo "<option>".$myrow["group_name"]."</option>\n";
	}
       	echo "</select>";

}
echo "</TR></form>";

// Show group footer
       if($group_name != "" and $group_myrow['group_footer'] != "")
       {  
           echo "<tr><td colspan=3><hr>";
           echo $group_myrow['group_footer'];
           echo "<hr></td></tr>";
       }
echo "</TABLE>";
//Start (Pagination) Check
$pageNum = $_REQUEST["start"];
//
if ($start != NULL OR $start != ''){
 if ($start > $nume){
    while($start>$nume)
    {
     $start=$start-$limit;
    }
 }
 $stDis='start='.$eu.'&';
}
$link3 = "index${page_ext_qry}".$alpha.$search.$pSort.$pOrder;
 //Prev & Next Buttons
if ( $limit < $nume) {
echo "<table align = 'center' width='25%'><tr><td align='left' width='15%'>";
      if($back >=0) {
        print "<a href=".$link3."start=".$back."><font face='Verdana' size='2'>PREV</font></a>";
      }
      echo "</td><td align=center width='70%'>";
      $i=0;
      $l=1;
      for($i=0;$i < $nume;$i=$i+$limit){
      if($i <> $eu){
            echo " <a href=".$link3."start=".$i."><font face='Verdana' size='2'>$l</font></a> ";
      }
      else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
      $l=$l+1;}
      echo "</td><td align='right' width='15%'>";
      if($this2 < $nume) {
               print "<a href=".$link3."start=".$next."><font face='Verdana' size='2'>NEXT</font></a>";}
      echo "</td></tr></table>";
 }//End Prev & Next buttons
 
include("include/footer.inc.php");

?>

 

Any idea on how to make this functional? I currently have it setup to send through Outlook but would much rather use a script than Outlook. Thanks in advanced.

 

-Brandon

Edit my previous request. Can someone help me form an e-mail script based on my code?

I want to be able to select any row from the database diplayed in the table and send their first name, last name, and e-mail to a script that I can send e-mails with. I may already have a somewhat working e-mail script but it is based off a guide I found online and seems to have its own limitations. I want to be able to send the required info to the script before I get too far ahead. Thanks.

 

-Brandon

You said 'any' row.  So I am assuming that want to send email to a single person.

 

print out rows in the following way:

# FIRST GET THE PERSON'S NAME AND EMAIL FROM THE DATABASE

for (each row found in the database) {
     echo "<tr><a href=\"email.php?name=$name&email=$email\">$name</tr>";
}

 

Then in the email script do something like:

$name = $_GET['name'];
$email = $_GET['email'];

$message = "<html><body><p>Please Hello, how are you $name?</p></body></html>';
mail("$email", 'Hello',
                	        "$message",
                        	"To: $name <$email>\n" .
                        	"From: mysite <[email protected]>\n" .
        	                "MIME-Version: 1.0\n" .
                	        "Content-type: text/html; charset=iso-8859-1");

test.JPG

This is what the bottom of my table looks like for my testing database. I want to be able to click the select boxes which are marker with 'id' and use their stored e-mail and names to send to another script (mail.php or something).  That way all I have to do is enter the subject and message and I can mass e-mail them.

 

I need help with gathering the information from the database based on the ticked selection boxes (hidden 'id' number) into an array. I have a button in place at the bottom but it uses a javascript to send the info over to Outlook. I want to cut Outlook out of this process.

 

-Brandon

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.