Hello PhP-lovers,
I got a problem for a few weeks with a mailscript.
I want people from my MYSQL database sending a mail ( Looks familiar?) I looked on a lot of places to find the solution, but still desparate...
Well, I want to combine underneath script.
-making connection..
-selecting the categories from my table.
-making the mail.
-inserting the variabels from database.
I know there are problems in this part:
while($row = mysql_fetch_array($result))
{
for($nr=0; $nr<$c; $nr++) {
$chk_sent = mail($recipient,$subject,$message,$headers);
}
This is what i got: ( maybe you know what i did wrong)
<?php
@ $db = mysql_connect('localhost', 'naam', 'password');
if (!db)
{
echo 'Error: Kon geen connectie met de database maken. Probeert u het later nog eens.';
exit;
}
mysql_select_db("mailing");
$result = mysql_query('SELECT geslacht, voorletters, tussenvoegsel, achternaam FROM mailinglist');
if (!$result) {
die('Could not query:' . mysql_error());
}
while($row = mysql_fetch_array($result))
{
for($nr=0; $nr<$c; $nr++) {
$chk_sent = mail($recipient,$subject,$message,$headers);
}
$message ='
<html>
<head>
<title>Nieuwsbrief</title>
<style type="text/css">
body{
background-color: #FFFF00;
color: #FF00FF;
}
</style>
</head>
<body>
<h4>Dear {name} {lastname},</h4>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td><img border="0" src="http://www.mijnsite.nl/afbeeldingen/b00.jpg" width="120" height="121"></td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td></td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
if (!$email) {
$email = "Mark<me@hccnet.nl>";
}
$message = ereg_replace("{name}", $name, $message);
$message = ereg_replace("{lastname}", $lastname, $message);
/ recipients /
$to = "me@hccnet.nl" . ", " ; // note the comma
$to .= "friend@hetnet.nl";
/ subject /
$subject = "Nieuwsbrief";
/ To send HTML mail, you can set the Content-type header. /
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
/ additional headers /
$headers .= "To: Mark <me@hccnet.nl>, Mark <me@hccnet.nl>\r\n";
$headers .= "From: Mijn site<info@mijnsite.nl>\r\n";
$headers .= "Bcc: $groep \r\n";
if ($chk_sent) {
print "<font color=\"black\">sent!\n";
} else {
print "<font color=\"black\">not sent!\n";
}
?>
Thanks sofar...