Connecting Tech Pros Worldwide Forums | Help | Site Map

Need help integrating function in a form (PHP?)

Newbie
 
Join Date: Jun 2008
Posts: 3
#1: Jun 25 '08
Hello! I just want to start with saying that i hope i'm asking the question in the right part of the forum. Maybe it should have been in the PERL section or some other section? Feel free to move the thread if this is so.

To the Q:

I have a simple contact-form in my website that looks like this:


Expand|Select|Wrap|Line Numbers
  1. <FORM action=http://www.domain.com/cgi-bin/FormMail.pl method=post><INPUT type=hidden value=info@domain.com name=recipient> <INPUT type=hidden value=kontakt@domain.com name=subject> <INPUT type=hidden value=http://www.domain.com/english/thanx.html name=redirect>
  2.  
  3. Name <INPUT size=50 name=Name><BR>
  4.  
  5. <P></P>E-mail <INPUT size=30 name=email><BR>  <BR>
  6.  
  7. <P>Message: <BR><TEXTAREA name=Meddelande rows=7 cols=50></TEXTAREA></P>
  8. </SELECT>
  9.  
  10. <P></P>
  11.  
  12. <P><INPUT type=submit value=Send! name=skicka> <INPUT type=reset value="Clear .." name=rensa></P></FORM>

As you see, I'm using the mailscript "FormMail.pl" that is provided by my host.

I also use a mailinglist on my site. The mailinglist i use is called "Listmessenger" and works well for me. The code i use to integrate listmessenger on the webpage looks like this:

Expand|Select|Wrap|Line Numbers
  1. <form action="http://www.domain.com/listmessenger/public/listmessenger.php" method="post">
  2.  
  3. <input type="text" name="email_address" value="" maxlength="128"> 
  4.  
  5.         <select name="action">
  6.         <option value="subscribe">Subscribe</option>
  7.         <option value="unsubscribe">Unsuscribe</option>
  8.  
  9.         </select>
  10.         <input type="hidden" name="group_ids[]" value="2" />
  11.         <input type="submit" value="Send" />
  12.  
  13. </form>
What i would like to do is to put a "checkbox" on the first form that if checked would also subscribe people to the mailinglist (send the "name" and "e-mail" part of the first form to "listmessenger.php" with the appropiate information that is in the second form").

Something like this maybe:

Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE=CHECKBOX NAME="maillist">Yes! Put me on the list!<P>
  2.  
I have to emphasize that i do not know alot of programing.
I know superbasic HTML/CSS and can do simple adjustments to already made PHP code, so if anybody sees a simple solution i would be really greatful.

Thanx for reading
/Daniel

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Jun 25 '08

re: Need help integrating function in a form (PHP?)


Welcome to the forum, Daniel!

First off, I'd like to mention writing html elements in UPPERCASE is no-longer acceptable! lowercase is the way we do it. :) Anotherthing, when you assign a value to an attribute, you always use quotes. name="name" value="yes".

On to the PHP:

You could simply add an IF conditional check to see if the checkbox was.. checked - alot of checks in this here sentence. Anyway, here's an example.

[php]
# add to mailinglist
if( isset ( $_POST['maillist'] ) )
{
# we'll need to do some database work here
$query = "INSERT INTO `tbl_name` ('name', 'email') VALUES ('{$_POST['escaped_name']}', '{$_POST['escaped_email']}')";
# do the actual query
$query = mysql_query($query) or die(mysql_error());
# check if query ran
if($query)
{
# email inserted
}
else
{
# wasnt inserted - problem.
}
}
[/php]
Let me know if you need some further help!
Newbie
 
Join Date: Jun 2008
Posts: 3
#3: Jul 13 '08

re: Need help integrating function in a form (PHP?)


Hello markus!

Thank you for replying to my request and sorry for not coming with feedback sooner.... You pointers are really helpfull btw....

Im sorry for beeing such a super-beginner but I really can't wrap my head around how to apply the code you suggested...and work further on it....

Are you thinking i should put the code inside of "mailinglist.php" or should i make my "contact.html" into a php and aply the checking-php-code there...?

Also the database work you are refering to..... *blushing*

As you see im really kind of lost but i do want to learn....so if you have the patience im really grateful....

The page i want to put the "checkbox" on is this one:
http://www.telluskultur.se/english/kontakt.html

Thanx
/Danielo
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#4: Jul 13 '08

re: Need help integrating function in a form (PHP?)


Quote:

Originally Posted by livingreality2012

Hello markus!

Thank you for replying to my request and sorry for not coming with feedback sooner.... You pointers are really helpfull btw....

Im sorry for beeing such a super-beginner but I really can't wrap my head around how to apply the code you suggested...and work further on it....

Are you thinking i should put the code inside of "mailinglist.php" or should i make my "contact.html" into a php and aply the checking-php-code there...?

Also the database work you are refering to..... *blushing*

As you see im really kind of lost but i do want to learn....so if you have the patience im really grateful....

The page i want to put the "checkbox" on is this one:
http://www.telluskultur.se/english/kontakt.html

Thanx
/Danielo

Do not apologise! Everyone's been there.

So, listmessenger.php is the target file!

If you would like to post that file to this thread (use code tags) I will help you on inserting the code.

Kind regards.
Newbie
 
Join Date: Jun 2008
Posts: 3
#5: Jul 13 '08

re: Need help integrating function in a form (PHP?)


Hi again! Thanks for being so helpful.

Here comes the listmessenger.php code...
Quite alot of it..


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /*
  3.     ListMessenger - Professional Mailing List Management
  4.     Copyright © 2005 Silentweb [http://www.silentweb.ca]
  5.  
  6.     Developed By: Matt Simpson <msimpson@listmessenger.com>
  7.  
  8.     For the most recent version, visit the ListMessenger website:
  9.     [http://www.listmessenger.com]
  10.  
  11.     License Information is found in docs/licence.html
  12.     $Id: Exp $
  13. */
  14.  
  15. // Change the $LM_PATH variable in the eu_config.inc.php file in this directory.
  16. require_once("./public_config.inc.php");
  17.  
  18. if(!@file_exists($LM_PATH."includes/config.inc.php")) {
  19.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n";
  20.     echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
  21.     echo "<head>\n";
  22.     echo "    <title>ListMessenger Path Error</title>\n";
  23.     echo "    <style>\n";
  24.     echo "    table.error-table {\n";
  25.     echo "        width:                    60%;\n";
  26.     echo "        background-color:            #FFD9D0;\n";
  27.     echo "        border:                    1px #CC0000 solid;\n";
  28.     echo "        padding:                    5px\n";
  29.     echo "    }\n\n";
  30.     echo "    td.error-text {\n";
  31.     echo "        color:                    #000000;\n";
  32.     echo "        font-family:                Verdana, Arial, Helvetica, sans-serif;\n";
  33.     echo "        font-size:                11px;\n";
  34.     echo "        padding-right:                5px\n";
  35.     echo "    }\n";
  36.     echo "    </style>\n";
  37.     echo "</head>\n";
  38.     echo "<body>\n";
  39.     echo "<table cellspacing=\"1\" cellpadding=\"2\" border=\"0\" class=\"error-table\">\n";
  40.     echo "<tr>\n";
  41.     echo "    <td class=\"error-text\">\n";
  42.     echo "        The path to the ListMessenger directory that you've provided [<b>".$LM_PATH."</b>] appears to be invalid or PHP does not have permission to read files from this directory. Please ensure that you provide the full path from root to your ListMessenger program directory in the \$LM_PATH variable within this file [<b>".__FILE__."</b>].";
  43.     echo    "    </td>\n";
  44.     echo "</tr>\n";
  45.     echo "</table>\n";
  46.     echo "</body>\n";
  47.     echo "</html>\n";
  48.     exit;
  49. } else {
  50.     @ini_set("include_path", str_replace("\\", "/", $LM_PATH."/includes"));
  51.     @ini_set("allow_url_fopen", 1);
  52.     @ini_set("error_reporting",  E_ALL ^ E_NOTICE);
  53.     @ini_set("magic_quotes_runtime", 0);
  54.  
  55.     define("TOOLS_LOADED",    true);
  56.     require_once("eu_header.inc.php");
  57.  
  58.     if(!$ERROR) {
  59.         // Recognized actions for this file. (subscribe || unsubscribe)
  60.         switch($info["action"]) {
  61.             // SUBSCRIBE
  62.             case "subscribe" :
  63.                 // Error checking for group information.
  64.                 if(((@is_array($info["group_ids"])) && (@count($info["group_ids"]) < 1)) || (trim($info["group_ids"]) == "") || (!str_is_int(trim($info["group_ids"])))) {
  65.                     $ERROR++;
  66.                     $TITLE    = $language_pack["error_default_title"];
  67.                     $MESSAGE    = $language_pack["error_subscribe_no_groups"];
  68.                 } else {
  69.                     $groups = array();
  70.  
  71.                     if(@is_array($info["group_ids"])) {
  72.                         foreach($info["group_ids"] as $group_id) {
  73.                             $query    = "SELECT `group_name` FROM `".TABLES_PREFIX."groups` WHERE `groups_id`='".checkslashes($group_id)."'";
  74.                             $result    = $db->GetRow($query);
  75.                             if($result) {
  76.                                 $query    = "SELECT `users_id` FROM `".TABLES_PREFIX."users` WHERE `group_id`='".checkslashes($group_id)."' AND `email_address`='".checkslashes(trim(strtolower($info["email_address"])))."'";
  77.                                 $result    = $db->GetRow($query);
  78.                                 if((!$result) && (!@in_array($group_id, $groups))) {
  79.                                     $groups[] = $group_id;
  80.                                 }
  81.                             } else {
  82.                                 $ERROR++;
  83.                                 $TITLE    = $language_pack["error_default_title"];
  84.                                 $MESSAGE    = $language_pack["error_subscribe_group_not_found"];    
  85.                             }
  86.                         }
  87.                         if((!$ERROR) && (@count($groups) < 1)) {
  88.                             $ERROR++;
  89.                             $TITLE    = $language_pack["error_default_title"];
  90.                             $MESSAGE    = $language_pack["error_subscribe_email_exists"];
  91.                         }
  92.                     } else {
  93.                         if(trim($info["group_ids"]) != "") {
  94.                             $query    = "SELECT `group_name` FROM `".TABLES_PREFIX."groups` WHERE `groups_id`='".checkslashes(trim($info["group_ids"]))."'";
  95.                             $result    = $db->GetRow($query);
  96.                             if($result) {
  97.                                 $query    = "SELECT `users_id` FROM `".TABLES_PREFIX."users` WHERE `group_id`='".checkslashes(trim($info["group_ids"]))."' AND `email_address`='".checkslashes(trim(strtolower($info["email_address"])))."'";
  98.                                 $result    = $db->GetRow($query);
  99.                                 if($result) {
  100.                                     $ERROR++;
  101.                                     $TITLE    = $language_pack["error_default_title"];
  102.                                     $MESSAGE    = $language_pack["error_subscribe_email_exists"];
  103.                                 } else {
  104.                                     $groups[] = checkslashes(trim($info["group_ids"]));
  105.                                 }
  106.                             } else {
  107.                                 $ERROR++;
  108.                                 $TITLE    = $language_pack["error_default_title"];
  109.                                 $MESSAGE    = $language_pack["error_subscribe_group_not_found"];    
  110.                             }
  111.                         }
  112.                     }
  113.                 }
  114.  
  115.                 // Error checking for e-mail address information.
  116.                 if((!$info["email_address"]) || (trim($info["email_address"]) == "")) {
  117.                     $ERROR++;
  118.                     $TITLE    = $language_pack["error_default_title"];
  119.                     $MESSAGE    = $language_pack["error_subscribe_no_email"];
  120.                 } else {
  121.                     if(!valid_address(trim($info["email_address"]))) {
  122.                         $ERROR++;
  123.                         $TITLE    = $language_pack["error_default_title"];
  124.                         $MESSAGE    = $language_pack["error_subscribe_invalid_email"];
  125.                     } else {
  126.                         if(@in_array(trim(strtolower($info["email_address"])), $config[ENDUSER_BANEMAIL])) {
  127.                             $ERROR++;
  128.                             $TITLE    = $language_pack["error_default_title"];
  129.                             $MESSAGE    = $language_pack["error_subscribe_banned_email"];
  130.                         } else {
  131.                             $address = explode("@", trim(strtolower($info["email_address"])));
  132.                             if(@in_array($address[1], $config[ENDUSER_BANDOMS])) {
  133.                                 $ERROR++;
  134.                                 $TITLE    = $language_pack["error_default_title"];
  135.                                 $MESSAGE    = $language_pack["error_subscribe_banned_domain"];
  136.                             } else {
  137.                                 if($config[ENDUSER_MXRECORD] == "yes") {
  138.                                     if((@getmxrr($address[1].".", $mxhosts) == false) && (@gethostbyname($address[1].".") == $address[1].".")) {
  139.                                         $ERROR++;
  140.                                         $TITLE    = $language_pack["error_default_title"];
  141.                                         $MESSAGE    = $language_pack["error_subscribe_invalid_domain"];
  142.                                     }
  143.                                 }
  144.                             }
  145.                         }
  146.                     }
  147.                 }
  148.  
  149.                 // Error checking for custom field information.
  150.                 $query    = "SELECT `field_sname`, `field_lname`, `field_req` FROM `".TABLES_PREFIX."cfields` ORDER BY `field_order` ASC";
  151.                 $results    = $db->GetAll($query);
  152.                 if($results) {
  153.                     $custom_data    = array();
  154.                     foreach($results as $result) {
  155.                         $field_completed = true;
  156.  
  157.                         if(isset($info[$result["field_sname"]])) {
  158.                             if(@is_array($info[$result["field_sname"]])) {
  159.                                 if(@count($info[$result["field_sname"]]) > 0) {
  160.                                     $custom_data[$result["field_sname"]] = checkslashes(html_encode(implode(", ", $info[$result["field_sname"]])));
  161.                                 } else {
  162.                                     $field_completed = false;    
  163.                                 }
  164.                             } else {
  165.                                 if(strlen(trim($info[$result["field_sname"]])) > 0) {
  166.                                     $custom_data[$result["field_sname"]] = checkslashes(html_encode($info[$result["field_sname"]]));
  167.                                 } else {
  168.                                     $field_completed = false;
  169.                                 }
  170.                             }
  171.                         }  else {
  172.                             $field_completed = false;
  173.                         }
  174.  
  175.                         if(($result["field_req"] == "1") && (!$field_completed)) {
  176.                             $ERROR++;
  177.                             $TITLE    = $language_pack["error_default_title"];
  178.                             $MESSAGE    = str_replace("[cfield_name]", $result["field_lname"], $language_pack["error_subscribe_required_cfield"]);
  179.                         }
  180.  
  181.                     }
  182.                 }
  183.                 if(!$ERROR) {
  184.                     if($config[ENDUSER_SUBCON] == "yes") {
  185.                         $result = users_queue(trim($info["email_address"]), html_encode(trim($info["firstname"])), html_encode(trim($info["lastname"])), $groups, $custom_data, "usr-subscribe");
  186.                         if($result) {
  187.                             @ini_set("sendmail_from", $config[PREF_ERREMAL_ID]);
  188.  
  189.                             $mail = new PHPMailer();
  190.                             $mail->PluginDir = $LM_PATH."includes/classes/phpmailer/";
  191.                             $mail->SetLanguage("en", $LM_PATH."includes/classes/phpmailer/language/");
  192.  
  193.                             switch($config[PREF_MAILER_BY_ID]) {
  194.                                 case "mail" :
  195.                                     $mail->IsMail();
  196.                                 break;
  197.                                 case "smtp" :
  198.                                     $mail->IsSMTP();
  199.                                     $mail->Host             = $config[PREF_MAILER_BY_VALUE];
  200.                                     $mail->SMTPAuth         = $config[PREF_MAILER_AUTH_ID];
  201.                                     if($mail->SMTPAuth) {
  202.                                         $mail->Username     = $config[PREF_MAILER_AUTHUSER_ID];
  203.                                         $mail->Password     = $config[PREF_MAILER_AUTHPASS_ID];
  204.                                     }
  205.                                     $mail->SMTPKeepAlive    = true;
  206.                                 break;
  207.                                 case "sendmail" :
  208.                                     $mail->IsSendmail();
  209.                                     $mail->Sendmail = $config[PREF_MAILER_BY_VALUE];
  210.                                 break;
  211.                             }
  212.  
  213.                             $mail->Priority    = 3;    // Normal
  214.                             $mail->CharSet        = $config[PREF_DEFAULT_CHARSET];
  215.                             $mail->Encoding    = "8bit";
  216.                             $mail->WordWrap    = $config[PREF_WORDWRAP];
  217.  
  218.                             $mail->From         = $config[PREF_FRMEMAL_ID];
  219.                             $mail->FromName    = $config[PREF_FRMNAME_ID];
  220.  
  221.                             $mail->Sender        = $config[PREF_ERREMAL_ID];
  222.  
  223.                             $mail->AddReplyTo($config[PREF_RPYEMAL_ID], $config[PREF_FRMNAME_ID]);
  224.  
  225.                             $mail->AddCustomHeader("X-ListMessenger-Version: ".VERSION_TYPE." [".VERSION_INFO."]");
  226.                             $mail->AddCustomHeader("X-ListMessenger-ID: ".urlencode($config[REG_SERIAL]));
  227.                             $mail->AddCustomHeader("X-Originating-IP: ".$_SERVER["REMOTE_ADDR"]);
  228.  
  229.                             $mail->Subject        = $language_pack["subscribe_confirmation_subject"];
  230.                             $mail->Body        = str_replace(array("[name]", "[url]", "[abuse_address]", "[from]"), array(checkslashes(trim($info["firstname"]), 1), ($config[PREF_PUBLIC_URL].$config[ENDUSER_CONFIRM_FILENAME]."?id=".$result["confirm_id"]."&code=".$result["hash"]), $config[PREF_ABUEMAL_ID], $config[PREF_FRMNAME_ID]), $language_pack["subscribe_confirmation_message"]);
  231.  
  232.                             $mail->ClearAddresses();
  233.  
  234.                             if(strlen(trim($info["firstname"])) > 1) {
  235.                                 $senders_name = checkslashes(trim($info["firstname"]), 1).((strlen(trim($info["lastname"])) > 1) ? " ".checkslashes(trim($info["lastname"]), 1) : "");
  236.                             } else {
  237.                                 $senders_name = trim($info["email_address"]);
  238.                             }
  239.                             $mail->AddAddress(trim($info["email_address"]), $senders_name);
  240.  
  241.                             if(@$mail->Send()) {
  242.                                 $TITLE    = $language_pack["success_subscribe_optin_title"];
  243.                                 $MESSAGE    = $language_pack["success_subscribe_optin_message"];
  244.                             } else {
  245.                                 $ERROR++;
  246.                                 $TITLE    = $language_pack["error_default_title"];
  247.                                 $MESSAGE    = $language_pack["error_subscribe_failed_optin"];
  248.  
  249.                                 $query = "DELETE FROM `".TABLES_PREFIX."confirmation` WHERE `confirm_id`='".$result["confirm_id"]."';";
  250.                                 if(!$db->Execute($query)) {
  251.                                     if($config[PREF_ERROR_LOGGING] == "yes") {
  252.                                         @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to delete the failed confirmation queue request from the confirmation table. Database server said: ".$db->ErrorMsg()."\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  253.                                     }
  254.                                 }
  255.                                 if($config[PREF_ERROR_LOGGING] == "yes") {
  256.                                     @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to send test message to ".$email_address.". PHPMailer said: ".$mail->ErrorInfo."\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  257.                                 }
  258.                             }
  259.  
  260.                             if($mail->Mailer == "smtp") $mail->SmtpClose();
  261.  
  262.                             $mail->ClearCustomHeaders();
  263.  
  264.                             @ini_restore("sendmail_from");
  265.                         } else {
  266.                             $ERROR++;
  267.                             $TITLE    = $language_pack["error_default_title"];
  268.                             $MESSAGE    = $language_pack["error_subscribe_email_exists"];
  269.  
  270.                             if($config[PREF_ERROR_LOGGING] == "yes") {
  271.                                 @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to add a new subscriber to the confirmation queue. The subscriber is already present in all groups.\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  272.                             }
  273.                         }
  274.                     } else {
  275.                         $result = users_add(trim($info["email_address"]), html_encode(trim($info["firstname"])), html_encode(trim($info["lastname"])), $groups, $custom_data);
  276.                         if($result) {
  277.                             $query    = "INSERT INTO `".TABLES_PREFIX."confirmation` VALUES ('', '".time()."', 'usr-subscribe', '".addslashes($_SERVER["REMOTE_ADDR"])."', '".addslashes($_SERVER["HTTP_REFERER"])."', '".addslashes($_SERVER["HTTP_USER_AGENT"])."', '".trim($info["email_address"])."', '".html_encode(trim($info["firstname"]))."', '".html_encode(trim($info["lastname"]))."', '".addslashes(serialize($groups))."', '".addslashes(serialize($custom_data))."', '', '0');";
  278.                             $db->Execute($query);
  279.  
  280.                             if($config[ENDUSER_NEWSUBNOTICE] == "yes") {
  281.                                 if(!send_notice("subscribe", array("email_address" => trim($info["email_address"]), "groups" => $groups))) {
  282.                                     if($config[PREF_ERROR_LOGGING] == "yes") {
  283.                                         @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to send new subscriber notice to administrator.\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  284.                                     }
  285.                                 }
  286.                             }
  287.  
  288.                             if($result["failed"] > 0) {
  289.                                 $ERROR++;
  290.                                 $TITLE    = $language_pack["error_default_title"];
  291.                                 $MESSAGE    = $language_pack["error_subscribe_failed"];
  292.                             }
  293.                             if($result["success"] > 0) {
  294.                                 $TITLE    = $language_pack["success_subscribe_title"]; 
  295.                                 $MESSAGE    = $language_pack["success_subscribe_message"];
  296.                             }
  297.                         } else {
  298.                             $ERROR++;
  299.                             $TITLE    = $language_pack["error_default_title"];
  300.                             $MESSAGE    = $language_pack["error_subscribe_email_exists"];
  301.  
  302.                             if($config[PREF_ERROR_LOGGING] == "yes") {
  303.                                 @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to add a new subscriber to the database. The subscriber is already present in all groups.\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  304.                             }
  305.                         }
  306.                     }
  307.                 }
  308.             break;
  309.  
  310.             // UNSUBSCRIBE
  311.             case "unsubscribe" :
  312.                 // Error checking for group information.
  313.                 if(((@is_array($info["group_ids"])) && (@count($info["group_ids"]) < 1)) || (trim($info["group_ids"]) == "") || (!str_is_int(trim($info["group_ids"])))) {
  314.                     $ERROR++;
  315.                     $TITLE    = $language_pack["error_default_title"];
  316.                     $MESSAGE    = $language_pack["error_unsubscribe_no_groups"];    
  317.                 } else {
  318.                     $groups            = array();
  319.                     $subscriber_ids    = array();
  320.                     if(@is_array($info["group_ids"])) {
  321.                         foreach($info["group_ids"] as $group_id) {
  322.                             $query    = "SELECT `group_name` FROM `".TABLES_PREFIX."groups` WHERE `groups_id`='".checkslashes(trim($group_id))."'";
  323.                             $result    = $db->GetRow($query);
  324.                             if($result) {
  325.                                 $query    = "SELECT `users_id` FROM `".TABLES_PREFIX."users` WHERE `group_id`='".checkslashes(trim($group_id))."' AND `email_address`='".checkslashes(trim(strtolower($info["email_address"])))."'";
  326.                                 $result    = $db->GetRow($query);
  327.                                 if(($result) && (!@in_array($result["users_id"], $subscriber_ids))) {
  328.                                     $subscriber_ids[]    = $result["users_id"];
  329.                                     $groups[]            = $group_id;
  330.                                 }
  331.                             } else {
  332.                                 $ERROR++;
  333.                                 $TITLE    = $language_pack["error_default_title"];
  334.                                 $MESSAGE    = $language_pack["error_unsubscribe_group_not_found"];    
  335.                             }
  336.                         }
  337.                         if((!$ERROR) && (@count($subscriber_ids) < 1)) {
  338.                             $ERROR++;
  339.                             $TITLE    = $language_pack["error_default_title"];
  340.                             $MESSAGE    = $language_pack["error_unsubscribe_email_not_exists"];
  341.                         }
  342.                     } else {
  343.                         if((trim($info["group_ids"]) != "") && (str_is_int($info["group_ids"]))) {
  344.                             $query    = "SELECT `group_name` FROM `".TABLES_PREFIX."groups` WHERE `groups_id`='".checkslashes(trim($info["group_ids"]))."'";
  345.                             $result    = $db->GetRow($query);
  346.                             if($result) {
  347.                                 $query    = "SELECT `users_id` FROM `".TABLES_PREFIX."users` WHERE `group_id`='".checkslashes(trim($info["group_ids"]))."' AND `email_address`='".checkslashes(trim(strtolower($info["email_address"])))."'";
  348.                                 $result    = $db->GetRow($query);
  349.                                 if($result) {
  350.                                     $subscriber_ids[]    = $result["users_id"];
  351.                                     $groups[]            = checkslashes(trim($info["group_ids"]));
  352.                                 } else {
  353.                                     $ERROR++;
  354.                                     $TITLE    = $language_pack["error_default_title"];
  355.                                     $MESSAGE    = $language_pack["error_unsubscribe_email_not_exists"];
  356.                                 }
  357.                             } else {
  358.                                 $ERROR++;
  359.                                 $TITLE    = $language_pack["error_default_title"];
  360.                                 $MESSAGE    = $language_pack["error_unsubscribe_group_not_found"];
  361.                             }
  362.                         }
  363.                     }
  364.                 }
  365.  
  366.                 // Error checking for e-mail address information.
  367.                 if((!$info["email_address"]) || (trim($info["email_address"]) == "")) {
  368.                     $ERROR++;
  369.                     $TITLE    = $language_pack["error_default_title"];
  370.                     $MESSAGE    = $language_pack["error_unsubscribe_no_email"];
  371.                 } else {
  372.                     if(!valid_address(trim($info["email_address"]))) {
  373.                         $ERROR++;
  374.                         $TITLE    = $language_pack["error_default_title"];
  375.                         $MESSAGE    = $language_pack["error_unsubscribe_invalid_email"];
  376.                     }
  377.  
  378.                     if(!$ERROR) {
  379.                         if($config[ENDUSER_UNSUBCON] == "yes") {
  380.                             $result = users_queue(trim($info["email_address"]), "", "", $groups, array(), "usr-unsubscribe");
  381.                             if($result) {
  382.                                 @ini_set("sendmail_from", $config[PREF_ERREMAL_ID]);
  383.  
  384.                                 $mail = new PHPMailer();
  385.                                 $mail->PluginDir = $LM_PATH."includes/classes/phpmailer/";
  386.                                 $mail->SetLanguage("en", $LM_PATH."includes/classes/phpmailer/language/");
  387.  
  388.                                 switch($config[PREF_MAILER_BY_ID]) {
  389.                                     case "mail" :
  390.                                         $mail->IsMail();
  391.                                     break;
  392.                                     case "smtp" :
  393.                                         $mail->IsSMTP();
  394.                                         $mail->Host             = $config[PREF_MAILER_BY_VALUE];
  395.                                         $mail->SMTPAuth         = $config[PREF_MAILER_AUTH_ID];
  396.                                         if($mail->SMTPAuth) {
  397.                                             $mail->Username     = $config[PREF_MAILER_AUTHUSER_ID];
  398.                                             $mail->Password     = $config[PREF_MAILER_AUTHPASS_ID];
  399.                                         }
  400.                                         $mail->SMTPKeepAlive    = true;
  401.                                     break;
  402.                                     case "sendmail" :
  403.                                         $mail->IsSendmail();
  404.                                         $mail->Sendmail = $config[PREF_MAILER_BY_VALUE];
  405.                                     break;
  406.                                 }
  407.  
  408.                                 $mail->Priority    = 3;    // Normal
  409.                                 $mail->CharSet        = $config[PREF_DEFAULT_CHARSET];
  410.                                 $mail->Encoding    = "8bit";
  411.                                 $mail->WordWrap    = $config[PREF_WORDWRAP];
  412.  
  413.                                 $mail->From         = $config[PREF_FRMEMAL_ID];
  414.                                 $mail->FromName    = $config[PREF_FRMNAME_ID];
  415.  
  416.                                 $mail->Sender        = $config[PREF_ERREMAL_ID];
  417.  
  418.                                 $mail->AddReplyTo($config[PREF_RPYEMAL_ID], $config[PREF_FRMNAME_ID]);
  419.  
  420.                                 $mail->AddCustomHeader("X-ListMessenger-Version: ".VERSION_TYPE." [".VERSION_INFO."]");
  421.                                 $mail->AddCustomHeader("X-ListMessenger-ID: ".urlencode($config[REG_SERIAL]));
  422.                                 $mail->AddCustomHeader("X-Originating-IP: ".$_SERVER["REMOTE_ADDR"]);
  423.  
  424.                                 $mail->Subject        = $language_pack["unsubscribe_confirmation_subject"];
  425.                                 $mail->Body        = str_replace(array("[url]", "[abuse_address]", "[from]"), array(($config[PREF_PUBLIC_URL].$config[ENDUSER_CONFIRM_FILENAME]."?id=".$result["confirm_id"]."&code=".$result["hash"]), $config[PREF_ABUEMAL_ID], $config[PREF_FRMNAME_ID]), $language_pack["unsubscribe_confirmation_message"]);
  426.  
  427.                                 $mail->ClearAddresses();
  428.                                 $mail->AddAddress(trim($info["email_address"]), trim($info["email_address"]));
  429.  
  430.                                 if(@$mail->Send()) {
  431.                                     $TITLE    = $language_pack["success_unsubscribe_optout_title"];
  432.                                     $MESSAGE    = $language_pack["success_unsubscribe_optout_message"];
  433.                                 } else {
  434.                                     $ERROR++;
  435.                                     $TITLE    = $language_pack["error_default_title"];
  436.                                     $MESSAGE    = $language_pack["error_unsubscribe_failed_optout"];
  437.  
  438.                                     $query = "DELETE FROM `".TABLES_PREFIX."confirmation` WHERE `confirm_id`='".$result["confirm_id"]."';";
  439.                                     if(!$db->Execute($query)) {
  440.                                         if($config[PREF_ERROR_LOGGING] == "yes") {
  441.                                             @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to delete the failed confirmation queue request from the confirmation table. Database server said: ".$db->ErrorMsg()."\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  442.                                         }
  443.                                     }
  444.                                     if($config[PREF_ERROR_LOGGING] == "yes") {
  445.                                         @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to send test message to ".$email_address.". PHPMailer said: ".$mail->ErrorInfo."\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  446.                                     }
  447.                                 }
  448.  
  449.                                 if($mail->Mailer == "smtp") $mail->SmtpClose();
  450.  
  451.                                 $mail->ClearCustomHeaders();
  452.  
  453.                                 @ini_restore("sendmail_from");
  454.                             } else {
  455.                                 $ERROR++;
  456.                                 $TITLE    = $language_pack["error_default_title"];
  457.                                 $MESSAGE    = $language_pack["error_unsubscribe_email_not_exists"];
  458.  
  459.                                 if($config[PREF_ERROR_LOGGING] == "yes") {
  460.                                     @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to add a new subscriber to the confirmation queue. The subscriber is already present in all groups.\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  461.                                 }
  462.                             }
  463.                         } else {
  464.                             $result = subscriber_remove($subscriber_ids);
  465.                             if($result) {
  466.                                 $query    = "INSERT INTO `".TABLES_PREFIX."confirmation` VALUES ('', '".time()."', 'usr-unsubscribe', '".addslashes($_SERVER["REMOTE_ADDR"])."', '".addslashes($_SERVER["HTTP_REFERER"])."', '".addslashes($_SERVER["HTTP_USER_AGENT"])."', '".trim($info["email_address"])."', '', '', '".addslashes(serialize($groups))."', '', '', '0');";
  467.                                 $db->Execute($query);
  468.  
  469.                                 if($config[ENDUSER_UNSUBNOTICE] == "yes") {
  470.                                     if(!send_notice("unsubscribe", array("email_address" => trim($info["email_address"]), "groups" => $groups))) {
  471.                                         if($config[PREF_ERROR_LOGGING] == "yes") {
  472.                                             @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to send unsubscribe notice to administrator.\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  473.                                         }
  474.                                     }
  475.                                 }
  476.  
  477.                                 $TITLE    = $language_pack["success_unsubscribe_title"]; 
  478.                                 $MESSAGE    = $language_pack["success_unsubscribe_message"];
  479.                             } else {
  480.                                 $ERROR++;
  481.                                 $TITLE    = $language_pack["error_default_title"];
  482.                                 $MESSAGE    = $language_pack["error_unsubscribe_email_not_exists"];
  483.  
  484.                                 if($config[PREF_ERROR_LOGGING] == "yes") {
  485.                                     @error_log(display_date("r", time())."\t".__FILE__." [Line: ".__LINE__."]\tUnable to remove subscriber from the database. They do not appear to be subscribed to the system.\n", 3, $config[PREF_PRIVATE_PATH]."logs/error_log.txt");
  486.                                 }
  487.                             }
  488.                         }
  489.                     }
  490.                 }
  491.             break;
  492.             default :
  493.                 $ERROR++;
  494.                 $TITLE    = $language_pack["error_default_title"];
  495.                 $MESSAGE    = $language_pack["error_invalid_action"];
  496.             break;    
  497.         }
  498.     }
  499.  
  500.     require_once("eu_footer.inc.php");
  501.  
  502.     @ini_restore("include_path");
  503.     @ini_restore("allow_url_fopen");
  504.     @ini_restore("error_reporting");
  505.     @ini_restore("magic_quotes_runtime");    
  506. }
  507. ?>
Reply