View Single Post
08-11-2012, 09:30 PM
#2
fde is offline fde
Status: I'm new around here
Join date: Aug 2012
Location: netherlands
Expertise: php
Software: xampp, cream for vim
 
Posts: 3
iTrader: 0 / 0%
 

fde is on a distinguished road

  Old

Imo you should use a cronjob which runs a php shell script.



This script set to run monthy in cron, connects to database, grabs the usernames and email adresses from db into array or object.

Then you do something like:
PHP Code:


$seperator
=" __ " 
$subject 'special code';
$headers 'From: webmaster@example.com' "\r\n" .
    
'Reply-To: webmaster@example.com' "\r\n" .
    
'X-Mailer: PHP/' phpversion();


foreach (
$users as $user){
 
$uniqspecode=md5($user['name']).$seperator.md5(time());
$to      =$user['email'];
$message 'Hi here is your special code: '.$uniqspecode;

mail($to$subject$message$headers);


When using object, its $user->name and $user->email
http://php.net/manual/en/language.oop5.php
http://php.net/mail
Make sure this script cannot be accessed directly from the internet, you don't want someone to visit http://yourdomain.com/script.php and send out a new batch of codes at every page refresh. One way to prevent this is instead of using <?php and ?>,
PHP Code:
#!/usr/bin/php 
in top of the script. Note you need the PHP CLI properly installed. Another way then cron is to just run the script manually every month via a protected login environment.

The seperator is provided to allow parsing of the specialcode and compare to md5 encrypted usernames, to determine which user it was.