Hello php-programmer,
I was trying to make a mailing.
and getting people names, gender and emailadres from my database records.
I have a nice MYSQL database containing:
id, gender, name, email, street, etc..
I have a code (bottom thread) and a few questions:
-get emailadresses + gender +names from records
-code how to attach my html (mostly) doc with images and sometimes attachments to the script.
-send these beautiful newsletters to all the persons in the records.
-and, but this is because of some writers scared me, explain what they mean with -q. It was some kind of delay, when you have to many records in your table. In the future I hope to send more then 1000 people my mailings... (Yess, they were added on free will, because I disgust those viagra and enlargement spam...
just a dream. :-} )
ps: Can I do the job smooth and nice without PEAR? I would like to.
Please help us all with this neverending subject:
Thanks !
Yess... the way I brought my subject above, is the way i surfed at Google... AND through www.phpbuider.com, advice:
it would help everyone if in the future more people put their questions in similar way.
Anyway, i have found this sofar:
<?php
$datab="";
$result = mysql_query('SELECT * FROM test');
if (!$result) {
die('Could not query:' . mysql_error());
}
$c=mysql_num_fields($result);
$n=mysql_list_fields($database,test);
for ($i = 0; $i < $c; $i++) {
$datab.= mysql_field_name($n, $i) . " - ";
}
$datab.= "\n";
while($row = mysql_fetch_array($result))
{
for($i=0;$i<$c;$i++)
{
$datab.=$row[$i]." - ";
}
$datab.="\n";
}
if (!$email) {
$email = "My Name<MyEmail@MyDomain.com>";
}
$nrecipient = "test@hotmail.com";
$nsubject = 'Email Database';
$nheaders = "From: $email\r\n";
$nheaders .= "CC: MyBackupemail@mydomain.com\r\n";
$nheaders .= "Importance: high\r\n";
$nheaders .= "X-Priority: 1\r\n";
$nheaders .= "X-MSMail-Priority: High\r\n";
$nheaders .= "Organization: MyDomain.com\r\n";
$chk_sent = mail($nrecipient,$nsubject,$datab,$nheaders);
if ($chk_sent) {
print "<font color=\"black\">sent!\n";
} else {
print "<font color=\"black\">not sent!\n";
}
/ recipients /
$to = "peoples@peoples.nl" . ", " ; // note the comma
$to .= "you@peoples.nl";
/ subject /
$subject = "Birthday";
/ message /
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
<style type="text/css">
body{
background-color: #FFFF00;
color: #FF00FF;
}
</style>
</head>
<body>
<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.site.nl/place/b00.jpg" width="120" height="121"></td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
/ 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: John <John@hccnet.nl>, Willem <willem@peoples.nl>\r\n";
$headers .= "From: Me
<info@me.nl>\r\n";
/ and now mail it /
mail($to, $subject, $message, $headers);
?>
above scripts are found on www.php.net/mail
and a forum on www.phpbuider.com.
My first question is:
Is it a wise decision to accomplish my job to mix these to scripts together? (I know it's variabels aren't integrated right, yet.)
second:
so now i only need $name $gender $email from my database which i have made; of course these information is seperated by records. Because I am not so far with MySQL yet, could someone please tell me how I go further?
$result = mysql_query('SELECT * FROM table');
I have to change this string into:
.........
And my tird and final question:
when we talk about mass mail <1000 is mail() wise? Yes I am specially interested in sending HTML with images, eventually maybe with attachments.
I hope you can combine code above or give some interesting help.
Marcus