Home › Forums › Back End › Newsletter › Re: Newsletter
I’m assuming by newsletter you want to send an email to a group of people.
I’ve never built something like this before, but I would do something like this.
Create a table in your database called "newsletter" with 3 fields
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 125 ) NOT NULL ,
`email` TEXT NOT NULL
) ENGINE = MYISAM ;
On your php file get all the rows from the table, and in the while loop send a message to each user. In addition, if an email fails, add it to an array so you can echo each recipients name and email address.
Thank you for subscribing to my website.
MSG;
while( $row = mysql_fetch_assoc($res) ) {
$new_subject = str_replace(“%name%”, $row[‘name’], $subject);
$new_message = str_replace(“%name%”, $row[‘name’], $message);
if( mail($row[’email’], $new_subject, $new_message) ) {
$sent_emails[] = “
Email Sent To: ” . $row[‘name’] . ” – ” . $row[’email’] . “
“;
}else
$failed_emails[] = “
Email Not Sent To: ” . $row[‘name’] . ” – ” . $row[’email’] . “
“;
}
foreach( $failed_emails as $message ) :
echo $message;
endforeach;
?>
(I haven’t tested this, but it should work)