( ! ) Notice: Undefined variable: header in C:\wamp64\www\ContactPHP\contact.php on line 5

Petit nouveau ! | 4 Messages

06 mars 2017, 21:06

J'ai ces deux erreurs : ( ! ) Notice: Undefined variable: header in C:\wamp64\www\ContactPHP\contact.php on line 5
Call Stack
# Time Memory Function Location
1 0.0004 236320 {main}( ) ...\contact.php:0

( ! ) 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:\wamp64\www\ContactPHP\contact.php on line 23
Call Stack
# Time Memory Function Location
1 0.0004 236320 {main}( ) ...\contact.php:0
2 0.0130 237664 mail ( ) ...\contact.php:23


Et voila le code de la page :

<?php
if(isset($_POST['mailform']))

$header="MIME-Version: 1.0\r\n";
$header.='From:"PrimFX.com"<[email protected]>'."\n";
$header.='Content-Type:text/html; charset="uft-8"'."\n";
$header.='Content-Transfer-Encoding: 8bit';

$message='
<html>
<body>
<div align="center">
<img src="http://www.primfx.com/mailing/banniere.png"/>
<br />
J\'ai envoyé ce mail avec PHP !
<br />
<img src="http://www.primfx.com/mailing/separation.png"/>
</div>
</body>
</html>
';

mail("[email protected]", "Salut tout le monde !", $message, $header);

?>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="stylecontact.css">
<title>Me contactez ! </title>
</head>
<body>
<i><h3><div align="center">Me contactez !</div></h3></i>
<form class="form_demo">
<input type="text" name="" placeholder="Email" class="inputbasic mail">
<input type="password" name="" placeholder="Entrée password" class="inputbasic">
<input type="submit"/>
<a href="contact.php">Conatct</a>





</form>
Merci de vos réponse
PS:Je débute.

Eléphant du PHP | 176 Messages

07 mars 2017, 01:05

Bonsoir

Alors
Notice: Undefined variable: header in C:\wamp64\www\ContactPHP\contact.php on line 5
vient de ta syntaxe de ton if
pour info un if/white/for/... sans accolade fait qu'uniquement la première instruction suivant ton if sera ce qui sera exécuté si ta condition est vraie

Pour faire simple
if(isset($_POST['mailform']))

$header="MIME-Version: 1.0\r\n";
$header.='From:"PrimFX.com"<[email protected]>'."\n";
$header.='Content-Type:text/html; charset="uft-8"'."\n";
$header.='Content-Transfer-Encoding: 8bit';
est strictement équivalent à
if(isset($_POST['mailform']))
{
    $header="MIME-Version: 1.0\r\n";
}
$header.='From:"PrimFX.com"<[email protected]>'."\n";
$header.='Content-Type:text/html; charset="uft-8"'."\n";
$header.='Content-Transfer-Encoding: 8bit';
Donc si ton $_POST['mailform'] n'existe pas la première instruction qui est exécuté est :
$header.='From:"PrimFX.com"<[email protected]>'."\n";
Ta variable $header n'est donc jamais initialisé et tu essaye directement d'ajouter du contenu à la suite de celui déjà existant (sauf que bah elle existe pas)

Ta deuxième erreur indique que tu n'as pas de serveur de mail (ou que tu n'as pas configuré correctement PHP)
Sous Linux il y a des solutions natives pour installer des serveurs de mail
Sous windows (windows desktop) il existe des "émulateurs" de serveur mail pour debugger
Cordialement
Naroth