I've followed this with interest, but unless you specifically need some 
properties of PHP to do this, use an easier tool.

Python has modules for both MySQL and PHP. They are easily invoked and 
don't involve calling Lynx & feeding it the script.
Here's some code, you might want to think about it as an alternative. I 
hope the indents preserve, as Python reliese on indentation and a <CR> ends 
it's line.

Miles Thompson


#! /usr/bin/python
"Mails Passwords from sub_list, a MySQL database "
import sys, MySQLdb, traceback
import rfc822, string, sys
import smtplib

# MySQLdb allows connection to the MySQL database
# This connects to the database, all parameters must be explicitly named
try:
    db = MySQLdb.connect( db='sub_list' )
except:
    traceback.print_exc()
    sys.exit()
# create connection to the database object
try:
    pcursor = db.cursor()
except:
    traceback.print_exc()
    sys.exit()
#let's display some information
print db.get_host_info()
print db.stat()

#let's fetch our data, mailing to everyone who has not been emailed a password
try:
         pcursor.execute("select * from subscriber where lpasswd_mailed = 0 
and email !='';")
         resultset = pcursor.fetchall()
except:
         traceback.print_exc()
         sys.exit()

#let's build the message
fromaddr = '[EMAIL PROTECTED]'
toaddr = '[EMAIL PROTECTED]'
username = ""
password = ""

msgFirstPart = "Thanks for subscribing. Passwords have been\n\
updated as part of our security schedule to protect your subscription. \n\
Your name and new password are: \n\n"

msgEndPart = "Please contact us at (555) 555-5555 or 555-5556 for help with 
your subscription, \n\
or email us at [EMAIL PROTECTED]\n\
\n\
Best regards, \n\
John Doe"

# we've gotten this far, so let's open the SMTP connection
server = smtplib.SMTP('smtp.domain.com',25)
server.set_debuglevel(2)

# for each record in the cursor
# set toaddr, username and password
# then send the message

# here in the for loop we send the mail message ....
#server.sendmail( fromaddr, toaddr, msg, "Subject: Your new password" )[D

for cursorRecord in resultset:
         toaddr = cursorRecord[ 3 ]
         first_name = "   First name: " + cursorRecord[ 2 ] + "\n"
         last_name = "   Last name: " + cursorRecord[ 1 ] + "\n"
         password = "   Password : " + cursorRecord[ 4 ] + "\n\n"
         msgMail = msgFirstPart + first_name + last_name + password + 
msgEndPart
         print msgMail
         server.sendmail( fromaddr, toaddr, msgMail, "Subject: Password for 
ALLnovascotia.com" )

         # build the update query
         upd_query = "update subscriber set lpasswd_mailed = 1 where email 
='" + cursorRecord[ 3 ] + "';"
         try:
                 #pcursor.execute( "update subscriber set lpasswd_mailed = 
1 where email = c_email;")
                 pcursor.execute( upd_query )
         except:
                 traceback.print_exc()
                 sys.exit()
print "\n\n"
print "All records printed"

#close the smpt connection
#server.quit()

# close the database
try:
    db.close()
except:
    traceback.print_exc()
    sys.exit()

# All done
print "*"*30
print ""
print "mailpass.py completed"
print ""
print "*"*30


At 02:58 AM 11/25/2001 -0500, you wrote:
>Thanks guys
>
>I just want to confirm one last thing, as it's been a while since I needed
>cron
>
>After I create this file (cron.file) for ex
>and use
>crontab cronfile (I do this as root, if it matters)
>do permissions need to be set? I really can't recall
>I would think that would do it as I am not uploading it
>and do it as root
>
>Thanks for the help, GREAT help and it's appreciated
>
>Now I just need to get freetype 2 installed right on my raq 3
>and I can live like a king
>
>Joel


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to