PHP & MY SQL - mailfunction

PHP & MY SQL - mailfunction

am 04.09.2006 12:31:43 von ghinzdra

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 rédaction envoi.html








bordercolor="navy" bordercolordark="navy" bordercolorlight="navy">



Sujet

:











Message
size="2">e :


























POUR LA PAGE ENVOI mail.php




Mailer




// le code qui nous permettra d'envoyer la lettre

$headers="from:wanadoo.fr";

// Connection à la base de donnée( par défaut paramètre 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 donnée

$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 récupérer 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 récupérés via le formulaire

// d'envoi
$sujet=$_POST["sujet"];
$message=$_POST["message"];
mail($email,$sujet,$message,$headers);

$i++;

}

// On ferme la connection

mysql_close();

?>







Thanks again