Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more  

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-05-2005, 02:44 PM   #1 (permalink)
goldfish
Junior Member
 
Join Date: Jul 2005
Posts: 27
Default php/mysql email registered users

Hi,

Okay I have a MySQL database with a php form that visitors can signup to receive the monthly newsletter. I have a field named 'email' in my form which stores the subscribers email address in the db field 'email'. I am looking for a php script that I can launch to email all users occationally and attach the newsletter. Anyone have a script like this they wish to share?

thanks
goldfish is offline   Reply With Quote
Sponsored Links
Old 09-11-2005, 06:40 PM   #2 (permalink)
redzone
Junior Member
 
Join Date: Jul 2005
Posts: 13
Default

Okay you have a db with a table and a field named 'email' that stores your visitors email address. So in this example your table name is 'contacts' and the field name is 'email'.

First the config file for mysql connection:
config.php
PHP Code:
<? 
$dbhost 
"localhost"
$dbname "yourdatabasename"
$dbuser "yourusername"
$dbpass "yourpassword"
?>
Now the form you will use to send the email or newsletter:
sendto.php
PHP Code:
<? 

if (!$_POST[send]) { 

echo 

<html> 
<head> 
<title>Send a Newsletter</title> 
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 

</head> 

<body> 
<font face='Verdana, Arial, Helvetica, sans-serif'><strong>Send a Newsletter</strong><br> 
</font> 
<form name='form1' id='form1' method='post' action='$_SERVER[PHP_SELF]'> 
  <table width='51%' border='0' cellpadding='5'> 
    <tr valign='top'> 
      <td width='47%'><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Subject:</font></strong></td> 
      <td width='53%'><input name='subject' type='text' size='25'></td> 
    </tr> 
    <tr valign='top'> 
      <td><strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Message 
        Body:</font></strong></td> 
      <td><textarea name='message' cols='50' rows='15'></textarea></td> 
    </tr> 
  </table> 
  <input name='send' type='hidden' id='send' value='ok'> 
  <br> 
  <input type='submit' name='Submit' value='Send'> 
  <input type='reset' name='Submit2' value='Reset'> 
</form> 
</body> 
</html> 
"

exit; 
} else { 

include 
'config.php'

// Checking validity 
if (!$_POST[subject] || !$_POST[message]) { 
header("Location: $_SERVER[PHP_SELF]"); 

exit; 



mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error()); 
mysql_select_db($dbname); 
$query mysql_query("SELECT email from contacts"); 

$headers "From: Yourname <your@emailaddress.com>\n"


while (
$result mysql_fetch_array($query)) { 
mail ($result[email],$_POST[subject],$_POST[message],$headers); 
echo 
"Newsletter has been sent to: $result[email]<br>"


?>
You only need to edit two lines with your own info in the sendto.php file:
your table
$query = mysql_query("SELECT email from contacts");
your email
($headers = "From: Yourname <your@emailaddress.com>\n";

Hope this helps
redzone is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 08:14 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums