Atlanticas Posted March 24, 2006 Share Posted March 24, 2006 I have a database with active users and wanted to know if is it possible to have my database send an email to a member when they are within 30 days of expiry? And finally, is it possible to create an area where I could email everyone? Like perhaps news/updates? Here is some coding that already sends an email when the member first registers that might help or what info is needed?[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php/*************************************************************************************************************************************************/class member{ var $dbu;function member() { $this->dbu=new mysql_db; }/***************************************************************** function add(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************//***************************************************************** function add(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function add(&$ld) { if(!$this->add_validate($ld)) { return false; } $join_date=strtotime("now"); $ld['exp_date']=date ("n/d/Y", mktime (0,0,0,date("n")+DEFAULT_EXPIRATION_INTERVAL,date("d"),date("Y"))); $exp_date = strtotime($ld['exp_date']); $birthdate = $ld['year']."-".$ld['month']."-".$ld['day']; $ld['member_id']=$this->dbu->query_get_id("insert into member ( name, country, address, address2, city, state, zip, email, username, password, join_date, exp_date, birthdate, phone, active1, active2 ) values ( '".$ld['name']."', '".$ld['country']."', '".$ld['address']."', '".$ld['address2']."', '".$ld['city']."', '".$ld['state']."', '".$ld['zip']."', '".$ld['email']."', '".$ld['username']."', '".$ld['password']."', '".$join_date."', '".$exp_date."', '".$birthdate."', '".$ld['phone']."', '0', '0' ) "); $this->send_client_notiffication_mail($ld); $ld['pn']="reg_success1"; return true; }/***************************************************************** function update(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function update(&$ld) { if(!$this->update_validate($ld)) { return false; } $birthdate = $ld['year']."-".$ld['month']."-".$ld['day']; $this->dbu->query("update member set country='".$ld['country']."', address='".$ld['address']."', address2='".$ld['address2']."', city='".$ld['city']."', state='".$ld['state']."', zip='".$ld['zip']."', email='".$ld['email']."', birthdate='".$birthdate."', phone='".$ld['phone']."', password='".$ld['password']."' where member_id='".$ld['member_id']."'" ); $ld['error'].=gettext("Your Profile has been successfully updated."); $ld['pn']="view_profile"; return true; }/***************************************************************** function activate1(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function activate1(&$ld){ if(!$this->activate1_validate($ld)){ return false; } $this->dbu->query("update member set active1='1' where member_id='".$ld['member_id']."'"); $this->send_admin_notiffication_mail($ld); //$ld['error'].="You have succesfully confirmed your Subscription Request.<br> Your account will be activated soon. "; $ld['pn']="reg_success"; return true;}/***************************************************************** function forgot(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function forgot(&$ld) { if(!$this->forgot_validate($ld)) { return false; } $this->dbu->query("select password, email from member where username='".$ld['username']."'"); $this->dbu->move_next(); $mail=$this->dbu->f('email'); $body="Hi ".$ld['username']." Here is your membership password: ".$this->dbu->f('password'); $header = "MIME-Version: 1.0\r\n"; $header.= "Content-Type: text\n"; $header.= "From: ".ADMIN_EMAIL." \n"; $mail_subject="Password Request"; @mail ( $mail , $mail_subject, $body , $header); $ld['pn']="forgot_success"; return true; }/***************************************************************** function send_admin_notiffication_mail(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function send_admin_notiffication_mail(&$ld) { $this->dbu->query("select * from member where member_id='".$ld['member_id']."'"); $this->dbu->move_next(); $body="There is a new Registration Request.User's data:Name - ".$this->dbu->f('name')."Address - ".$this->dbu->f('address')."Address 2 - ".$this->dbu->f('address2')."City - ".$this->dbu->f('city')."State - ".$this->dbu->f('state')."ZIP - ".$this->dbu->f('zip').";Country - ".$this->dbu->f('country')."Email - ".$this->dbu->f('email')."Username - ".$this->dbu->f('username')."Password - ".$this->dbu->f('password')." Please Check "; $header = "MIME-Version: 1.0\r\n"; $header.= "Content-Type: text\n"; $header.= "From: ".ADMIN_EMAIL." \n"; $mail_subject="New Registration Request"; @mail ( ADMIN_EMAIL , $mail_subject, $body , $header); return true; }/***************************************************************** function send_client_notiffication_mail(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function send_client_notiffication_mail(&$ld) { global $site_url, $site_name; $this->dbu->query("select * from member where member_id='".$ld['member_id']."'"); $this->dbu->move_next(); $mail=$this->dbu->f('email'); $body="You have made a Registration Request.Here is the data you submited:Name - ".$this->dbu->f('name')."Address - ".$this->dbu->f('address')."Address 2 - ".$this->dbu->f('address2')."City - ".$this->dbu->f('city')."State - ".$this->dbu->f('state')."ZIP - ".$this->dbu->f('zip')."Country - ".$this->dbu->f('country')."Email - ".$this->dbu->f('email')."Username - ".$this->dbu->f('username')."Password - ".$this->dbu->f('password')." To confirm your Registration Request please click the link below:".$site_url."index.php?fn=member-activate1&member_id=".$ld['member_id'].""; $header = "MIME-Version: 1.0\r\n"; $header.= "Content-Type: text\n"; $header.= "From: ".ADMIN_EMAIL." \n"; $mail_subject="Confirmation for ".$site_name; @mail ( $mail , $mail_subject, $body , $header); return true; }/***************************************************************** function add_validate(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function add_validate(&$ld){ $is_ok=true; if(!$ld['name']) { $ld['error'].="Please enter Your Name."."<br>"; $is_ok=false; } if(!$ld['address']) { $ld['error'].="Please enter Your Address."."<br>"; $is_ok=false; } if(!$ld['city']) { $ld['error'].="Please enter Your City."."<br>"; $is_ok=false; } if(!$ld['state']) { $ld['error'].="Please enter Your State."."<br>"; $is_ok=false; } if(!$ld['zip']) { $ld['error'].="Please enter Your Zip."."<br>"; $is_ok=false; } if(!$ld['country']) { $ld['error'].="Please enter Your Country."."<br>"; $is_ok=false; } if(!$ld['email']) { $ld['error'].="Please enter Your Email Adderss."."<br>"; $is_ok=false; } if($ld['email'] && !secure_email($ld['email'])) { $ld['error'].="Please insert a valid email address."."<br>"; $is_ok=false; } if(!$ld['username']) { $ld['error'].="Please enter Your Username."."<br>"; $is_ok=false; } elseif (!secure_string_no_spaces($ld['username'])) { $ld['error'].="Please enter a valid Username (no spaces)."."<br>"; $is_ok=false; } elseif (strlen($ld['username'])<6) { $ld['error'].="Please enter a valid Username (min. 6 chars)."."<br>"; $is_ok=false; } else { $this->dbu->query("select member_id from member where username='".$ld['username']."'"); if($this->dbu->move_next()) { $ld['error'].="There is another Member with this Username. Please change it."."<br>"; $is_ok=false; } } if(!$ld['password']) { $ld['error'].="Please enter a Password."."<br>"; $is_ok=false; } elseif (strlen($ld['password'])<6) { $ld['error'].="Please enter a valid Password (min. 6 chars)."."<br>"; $is_ok=false; } elseif (!secure_string_no_spaces($ld['password'])) { $ld['error'].="Please enter a valid Password (no spaces)."."<br>"; $is_ok=false; } elseif ($ld['password']!=$ld['password1']) { $ld['error'].="Password does not match."."<br>"; $is_ok=false; } return $is_ok;}/***************************************************************** function update_validate(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function update_validate(&$ld){ $is_ok=true; if (!is_numeric($ld['member_id'])) { $ld['error'].=gettext("Invalid Id.")."<br>"; return false; } $this->dbu->query("select member_id from member where member_id='".$ld['member_id']."'"); if(!$this->dbu->move_next()) { return false; } if(!$ld['address']) { $ld['error'].="Please enter Your Address."."<br>"; $is_ok=false; } if(!$ld['city']) { $ld['error'].="Please enter Your City."."<br>"; $is_ok=false; } if(!$ld['state']) { $ld['error'].="Please enter Your State."."<br>"; $is_ok=false; } if(!$ld['zip']) { $ld['error'].="Please enter Your Zip."."<br>"; $is_ok=false; } if(!$ld['country']) { $ld['error'].="Please enter Your Country."."<br>"; $is_ok=false; } if(!$ld['email']) { $ld['error'].="Please enter Your Email Adderss."."<br>"; $is_ok=false; } if($ld['email'] && !secure_email($ld['email'])) { $ld['error'].="Please insert a valid email address."."<br>"; $is_ok=false; } if ($ld['password'] && strlen($ld['password'])<6) { $ld['error'].="Please enter a valid Password (min. 6 chars)."."<br>"; $is_ok=false; } elseif (!secure_string_no_spaces($ld['password'])) { $ld['error'].="Please enter a valid Password (no spaces)."."<br>"; $is_ok=false; } elseif ($ld['password']!=$ld['password1']) { $ld['error'].="Password does not match."."<br>"; $is_ok=false; } if($is_ok && !$ld['password']) { $this->dbu->query("select password from member where member_id='".$ld['member_id']."'"); $this->dbu->move_next(); $ld['password']=$this->dbu->f('password'); } return $is_ok;}/***************************************************************** function activate1_validate(&$ld) ******************************************************************* @Description: ** ******************************************************************* @Parameters: ** &$ld ******************************************************************* @return *****************************************************************/function activate1_validate(&$ld){ if (!is_numeric($ld['member_id'])) { return false; } $this->dbu->query("select member_id from member where member_id='".$ld['member_id']."'"); if(!$this->dbu->move_next()) { return false; } return true;}//******************************forgot_validate*******************function forgot_validate(&$ld){ $this->dbu->query("select email from member where username='".$ld['username']."'"); if($this->dbu->move_next()) { $wrong_email=1; if($this->dbu->f('email')==$ld['email']) { $wrong_email=0; } if($wrong_email) { $ld['error']="Email Address does not match. <br>"; return false; } } else { $ld['error']="This Username does not exist in our database. <br>"; return false; } return true;}}//end class?>[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/5672-email-users-in-database/ 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.