|
Posted by ghinzdra on 09/04/06 10:31
Hi
I endeavor to implement a newsletter for my association . Here's my
situation : i use the classical duo PHP-MySQL in localhost for the moment
.. Considering the inscription in MySQL part , there's apparently no
problem . I use 2 pages PHP : one for the inscription itslef , another
one for heralding the success of the inscription process. The MySQL
database (prim) is successfuly changed : the table(lettre) has a single
field (mail) which displays the email adresses of the 2 emailboxes that i
filled in the form.
However as for the sending part there happens to have a problem . I
currently use 2 pages : a hmtl page (envoi.html) for the writing of my
newsletter and a php page for the sengin part itself (mail.php). The SMTP
key in the php.ini file is valued "localhost" . In the beginning the
following error message was printed by the browser :"Warning: mail():
Failed to connect to mailserver at "localhost" port 25, verify your
"SMTP" and "smtp_port" setting in php.ini or use ini_set() in c:\www
\newsletter\mail.php3 on line 48" . I guess i could not expect another
anwser seiing no SMTP server was installed at the localhost scale . I
activated Hamster that i'm used to carry out only for getting news on
Usenet for it seems to me that it offers a SMTP function (if i'm wrong
tell me so) . There was no hint of a mail in those emailboxes yet
(laposte.net and hotmail.com) .
So i have a single question and three ideas : where does it fail ?
1- is it at the MySQL level ? (even if the datas are correctly displayed
in the table itslef maybe the values are not put in the right place in
the PHP mail function )
2- is it at the PHP level ,more precisely is the mail function the
culprit? if it was so then an error message should be impressed in the
browser
3- is it at the SMTP level ? is Hamster ill-configured or unable to
carry out this task ?
Thanks , i hope that you were able to understand me
i put the code of the 2 pages
POUR LA PAGE HTML de rdaction envoi.html
<html>
</body>
<form method="post" action="mail.php3">
<table width="445" align="center" border="1" cellspacing="0"
bordercolor="navy" bordercolordark="navy" bordercolorlight="navy">
<tr><td width="130" align="right">
<p><font size="2" color="navy"><b>Sujet</b></font><font size="2">
<b> : </b></font></p>
</td><td width="311" align="left">
<p><font size="2"><input type="text" name="sujet" size="44">
</font></p>
</td></tr><tr><td width="130" align="right" valign="top" rowspan="2">
<p><font size="2" color="navy"><b>Message</b></font><font
size="2"><b>e : </b></font></p>
</td><td width="311">
<p><font size="2"><textarea name="message" rows="18"
cols="42"></textarea></font></p>
</td> </tr><tr><td width="311" align="left">
<p><font size="2"><input type="submit" value="Envoyer la newsletter">
<input type="reset" value="Rinitialiser"></font></p>
</td></tr></table>
</form>
</body>
</html>
POUR LA PAGE ENVOI mail.php
<html>
<head>
<title>Mailer</title>
</head>
<body>
<?
// le code qui nous permettra d'envoyer la lettre
$headers="from:wanadoo.fr";
// Connection la base de donne( par dfaut paramtre local)
$server="localhost";
$user="root";
$pass="mineraux";
$db="prim";
mysql_connect($server, $user, $pass) or die('Erreur de connexion');
mysql_select_db($db) or die('Base inexistante');
// on selectionne tous les emails de la base de donne
$req=mysql_query("SELECT email FROM lettre" );
// on compte le nombre d'emails
$res=mysql_numrows($req);
// On envoi la lettre d'info a tous les emails
// Utilisation d'une boucle while pour rcuprer tous les mails
// et envoi avec la fonction mail( ) placer dans la boucle...
$i=0;
while($i!=$res) {
$email=mysql_result($req,$i,"email" );
// Les variables sujet et message sont rcuprs via le formulaire
// d'envoi
$sujet=$_POST["sujet"];
$message=$_POST["message"];
mail($email,$sujet,$message,$headers);
$i++;
}
// On ferme la connection
mysql_close();
?>
</body>
</html>
Thanks again
[Back to original message]
|