0
I don’t know the right way to send data from a form to an email using PHP
.
So that’s the situation:
Page contato.php
:
<form id="form-contato" action="enviar.php" method="post">
<h2>Fale com nossa Equipe!</h2>
<label for="Nome">Nome:</label><input type="text" name="Nome" id="Nome" maxlength="40"><br><br>
<label for="E-mail">E-mail:</label><input type="email" name="E-mail" id="E-mail" maxlength="60"><br><br>
<label for="Assunto">Assunto:</label>
<select name="Assunto" id="Assunto">
<option selected disabled style="font-style:italic;">Selecione... </option>
<option value="Interesse em ser Assinante">Interesse em ser Assinante</option>
<option value="Reclamação">Reclamação</option>
<option value="Perguntas">Perguntas</option>
</select><br>
<p>Mensagem:</p>
<div id="textarea">
<textarea id="Mensagem" cols="50" rows="7" name="Mensagem"></textarea>
</div>
<input type="submit" value="Enviar">
</form>
Then the page enviar.php
:
<?php
$nome = $_POST['Nome'];
$email = $_POST['E-mail'];
$assunto = $_POST['Assunto'];
$mensagem = $_POST['Mensagem'];
$data_envio = date('d/m/Y');
$hora_envio = date('H:i:s');
//enviar
// emails para quem será enviado o formulário
$emailenviar = "[email protected]";
$destino = $emailenviar;
// É necessário indicar que o formato do e-mail é html
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '.$nome.' <'.$email.'>';
//$headers .= "Bcc: $EmailPadrao\r\n";
$arquivo = "";
$enviaremail = mail($destino, $assunto, $arquivo, $headers);
if($enviaremail){
$mgm = "E-MAIL ENVIADO COM SUCESSO! <br>
O link será enviado para o e-mail
fornecido no formulário";
echo " <meta http-equiv='refresh' content='10;URL=contato.php'>";
} else {
$mgm = "ERRO AO ENVIAR E-MAIL!";
echo "";
}
?>
So when I submit the form, nothing happens. It only goes to one page enviar.php
and does not give ERROR IN SENDING EMAIL and also does not give E-MAIL SENT SUCCESSFULLY. Just nothing happens, just a blank page.
I would like to know what are the errors of this code and also another doubt, is that just because I upload to the server of my site, is already running the email service?
Possible duplicate of How to send email with PHP?
– Gabplay
In case of error Voce is not showing anything. Try to replace the
echo "";
forecho $mgm;
.– rdleal
Yeah, now you’re making the same mistake. But how to solve?
– Nicolas S.
In this case I believe that the link that @Gabrielranéabarbosa commented should help you. But taking advantage of what you asked: just by the fact that I upload to the server of my site, the e-mail service is already working?, Your problem may be there, check if the function
mail
PHP is correctly configured on your server.– rdleal
I did some research on the function
mail
and got it now. Thank you!– Nicolas S.
Good @Nicolass. If none of the answers you have given have met your needs, I suggest you answer your own question describing how you solved it and mark your answer as correct. So whoever has the same problem Voce had can find their answer useful.
– rdleal