Users sign up on one page w/name and email. Email is checked for auth. Name and email added to Mysql database. "Broadcaster" fills out a form page with header, body, and footer of the email. Header and footer are saved for later. Mail is sent to all users in the database with a personal "Dear (name they entered)" at the top of the email. Sender can upload text, log off, and the script will continue to send out all emails. Sleep function for slowing down send rate. Log file written upon script completion of unsendable emails. Uses php mail() function (sendmail).
/* All code by David Fox except validateEmail function
Use it happily, anywhere, with credits.
You use this signup with send_mailing_list.php3 which sends the newsletter.
What would be really cool, since the letters will already be customized w/ the users name (if they enter it), is
another database table with user preferences linked to the mailing_list table. That would allow you to program some
cool stuff in send_mailing_list.php3 to add even more personalization... such as new products, headlines, whatever
the user actually wants to see. You could put checkboxes or dropdowns in here to select stuff.
REQUIRED:
MySQL table creation SQL:
CREATE TABLE mailing_list (id INT(30) NOT NULL PRIMARY KEY AUTO_INCREMENT, email VARCHAR(100) NOT NULL, name VARCHAR(100), timestamp TIMESTAMP, UNIQUE (email));
validateEmail function
By: Jon S. Stevens jon@clearink.com
Copyright 1998 Jon S. Stevens, Clear Ink
This code has all the normal disclaimers.
It is free for any use, just keep the credits intact.
It will return an array. $return[0] is whether it was a valid
email or not and $return[1] is the SMTP error message if there was one.*/
function validateEmail ($email){
global $SERVER_NAME;
$return = array(false, "" );
list ($user, $domain) = split( "@", $email, 2);
$arr = explode( ".", $domain);
$count = count ($arr);
$tld = $arr[$count - 2] . "." . $arr[$count - 1];
if(checkdnsrr($tld, "MX")) {
if(getmxrr($tld, $mxhosts, $weight)) {
for($i = 0; $i < count($mxhosts); $i++){
$fp = fsockopen($mxhosts[$i], 25);
if ($fp){
$s = 0;
$c = 0;
$out = "";
set_socket_blocking($fp, false);
do {
$out = fgets($fp, 2500);
if(ereg( "^220", $out)){
$s = 0;
$out = "";
$c++;
}
else if(($c > 0) && ($out == "")){
break;
}
else {
$s++;
}
if($s == 9999) {
break;
}
} while($out == "");
set_socket_blocking($fp, true);
fputs($fp, "HELO $SERVER_NAME\n");
$output = fgets ($fp, 2000);
fputs($fp, "MAIL FROM: <info@" . $tld . ">\n" );
$output = fgets($fp, 2000);
fputs($fp, "RCPT TO: <$email>\n");
$output = fgets($fp, 2000);
if(ereg( "^250", $output )) {
$return[0] = true;
}
else {
$return[0] = false;
$return[1] = $output;
}
fputs ($fp, "QUIT\n");
fclose($fp);
if($return[0] == true){
break;
}
}
}
}
}
return $return;
}
// format the email body so it has soft returns after set number chars
$message = "Thank you. You will receive a confirmation email soon to verify your subscription";
}
else {
// couldn't send mail, but db action was OK
$message = "You have been successfully subscribed, but here was a problem sending your confirmation email.<br>You should, however receive your newsletter soon.";
}
}
else {
$message = "Thank you. You should receive your newsletter soon.";
}
}
else {
// db error message
$confirm = False;
$message = "There was an error processing your subscription. Please wait a moment, and try again.<br>";
}
}
else {
// validateEmail came back false, display error.
$confirm = False;
$message = "Your email address appears to be a valid, but does not respond.<br>";
$message .= "Please check to see that the address is a valid email address";
}
}
else {
// ereg test failed. It doesn't even LOOK like an email address.
$confirm = False;
$message = "This does not appear to be a valid email address.<br>Please check to see that the address has been entered properly.<br>";
}
}
// they didn't enter anything
else { $message = "You must enter an email address to subscribe!"; }
}
else {
// default message
$message = "Enter your email address to sign up for the mailing list.";
print( "<tr align=\"center\"><td colspan=\"2\">Click here to receive a confirmation email <input type=\"checkbox\" name=\"confirmation\" value=\"true\" checked></td></tr>");
////////////// END FUNCTIONS ////////////////////////////////
define( "SENDER", "newsletter@mydomain.com");
define( "DATABASE", "mydb");
define( "HOST", "localhost");
define( "USER", "httpd");
define( "PASSWORD", "");
define( "SLEEP", 1); // amount of seconds to sleep between mailings. Usefull for mellowing out your mailing rate to be nice to the server. Can be zero.
// the script is set to contiue executing after you log off.. so set and forget.
// where you want the header and footer files to live