Cod PHP email - Help - eroare

Ai o întrebare legată de PHP? Incercăm să îi găsim soluţie. Sau poate doar vrei să publici un cod interesant.

Moderatori: Zamolxe, Moderatori

RamAdrian
New Member
Mesaje: 2
Membru din: Dum Ian 28, 2018 10:44 pm

Cod PHP email - Help - eroare

Mesajde RamAdrian » Dum Ian 28, 2018 10:55 pm

Salut,

Va rog ajutati-ma in urmatoare problema
Codul PHP imi returmeaza raspunsul de Succes (Mail Trimis)
Insa email-ul nu ajunge in inbox

Cod:

<body style ='background-color: black;'>

<div class="container">
<div class="row">
<div class="col-sm-12">

<?php
if(isset($_POST['trimis']))
{
$nume = $_POST['nume'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$subiect = $_POST['subiect'];
$mesaj = $_POST['mesaj'];
$body = $nume ."\n". $tel ."\n". $mesaj;
//$status = "necitit";

if((empty($nume)) !== false){
$error1 = "Nulele nu poate fi gol!";
}
if(empty($tel)){
$error2 = "Completati telefonul!";
}
if(empty($email)){
$error3 = "Email invalid!";
}
if(empty($subiect)){
$error6 = "Adaugati un subiect!";
}
if(empty($mesaj)){
$error4 = "Completati mesajul!";
}
if(!isset($error1)&!isset($error2)&!isset($error3)&!isset($error4)){
$headers = 'From: '.$email. "\r\n" .
'Reply-To:'.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail = mail('xxx@gmail.com',$subiect,$body,$headers);
if($mail){
$succes = "Mail trimis!";
}
else{
$error5 = "Mail netrimis";
}
}
}
?>

<p>Sau completand fornularul de mai jos</p>
<?php if (isset($error5)){?>
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Atentie! </strong>
<?php echo $error5 ?>

</div>
<?php
}
if (isset($succes)){?>
<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Multumim! </strong>
<?php echo $succes ?>

</div>
<?php
}
?>
<form action="contact.php" method="POST" style="padding-bottom: 200px;" class="form-horizontal" role="form">
<div class="form-group">
<?php if(isset($error1)){ ?>
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Atentie! </strong>
<?php echo $error1 ?>

</div>
<?php } ?>
<label class="control-label col-sm-2" for="nume" style="color: #ffffff">Numele:</label><br/>
<div class="col-sm-10">
<input type="text" name="nume" id="nume" class="form-control"> <br /><br />
</div>
</div>
<div class="form-group">
<?php if(isset($error2)){ ?>
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Atentie! </strong>
<?php echo $error2 ?>

</div>
<?php } ?>
<label class="control-label col-sm-2" for="tel" style="color: #ffffff">Telefon:</label><br />
<div class="col-sm-10">
<input type="tel" name="tel" id="tel" class="form-control"><br /><br />
</div>
</div>
<div class="form-group">
<?php if(isset($error3)){ ?>
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Atentie! </strong>
<?php echo $error3 ?>

</div>
<?php } ?>
<label class="control-label col-sm-2" for="email" style="color: #ffffff">E-mail:</label><br/>
<div class="col-sm-10">
<input type="email" name="email" id="email" class="form-control"><br/><br />
</div>
</div>
<div class="form-group">
<?php if(isset($error6)){ ?>
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Atentie! </strong>
<?php echo $error6 ?>

</div>
<?php } ?>
<label class="control-label col-sm-2" for="subiect" style="color: #ffffff">Subiect:</label><br/>
<div class="col-sm-10">
<input type="text" name="subiect" id="subiect" class="form-control"><br/><br />
</div>
</div>
<div class="form-group">
<?php if(isset($error4)){ ?>
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Atentie! </strong>
<?php echo $error4 ?>

</div>
<?php } ?>
<label class="control-label col-sm-2" for="mesaj" style="color: #ffffff">Mesaj:</label><br/>
<div class="col-sm-10">
<textarea name="mesaj" id="mesaj" class="form-control" style="height: 200px;"></textarea><br/><br/>
</div>
</div>
<div class="form-group">
<input type="hidden" name="trimis" value="true">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<input type="submit" value="Trimite" class="btn-default btn-lg">
</div>
<div class="col-sm-4">
<input type="reset" value="Reset" class="btn-default btn-lg">
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>



nevvermind
Senior Member
Mesaje: 1264
Membru din: Mar Iun 22, 2010 3:17 pm

Re: Cod PHP email - Help - eroare

Mesajde nevvermind » Lun Ian 29, 2018 10:57 am

Citez din http://php.net/manual/en/function.mail.php: "It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination".

Verifica logurile de mail (de prin /var/log/maillog sau /var/log/mail.log).

PS: Risti mult daca permiti valorilor din $_POST sa ajunga nefiltrate intr-un corp de email.
Facusi un canal de php pe freenode - ##php-ro : https://webchat.freenode.net/

RamAdrian
New Member
Mesaje: 2
Membru din: Dum Ian 28, 2018 10:44 pm

Re: Cod PHP email - Help - eroare

Mesajde RamAdrian » Dum Feb 04, 2018 4:22 pm

Salut,

Multumesc pentru raspuns

Dar cum pot verifica sau vedea daca serverul de PHP este configurat sa trimita mail?

Am gasit pe alte forumuri ca ar trebui sa edite fisierul PHP.ini , problema este ca nu gasesc acest fisier. Ma poate afuta cineva?

Desi nu am gasit fisierul de php.ini acum vad ca mail-urile sunt trimise (dupa ce am creat un cont de mail din cPanel), acum problema este ca aproape toate mail-urile sunt trimise in spam.


Înapoi la “Cod PHP”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 24 vizitatori