PF2G Posted August 30, 2011 Share Posted August 30, 2011 Hello!! Here's the thing: i'm working in a website about a Music School, and i'm having troubles with the 'Contact'. I created a form where people can question or say something and that message i want to be sent to my email. <?PHP include 'topo.php'; $refresh = '<meta http-equiv="refresh" content="1; url=form.html" />'; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<script type="text/javascript">alert("E-mail inválido!.")</script>'; exit ($refresh); } elseif (!filter_var($email, FILTER_SANITIZE_EMAIL)) { echo '<script type="text/javascript">alert("E-mail inválido!. Contém caracteres não permitidos.")</script>'; exit ($refresh); } if ($nome != '' && $email != '' && $texto != '') { $msg = "<strong>Nome:</strong> $nome<br>"; $msg .= "<strong>E-mail:</strong> $email<br>"; $msg .= "<strong>Mensagem:</strong> $texto<br>"; $recipient = "paulo.devil92@gmail.com"; $subject = "Contacto EMInfante"; $header = "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $header .= "From: $email\r\n"; if (mail ($recipient, $subject, $msg, $header)) { echo '<script type="text/javascript">alert("Contato enviado.")</script>'; exit ($refresh); } else { echo '<script type="text/javascript">alert("Problema no envio da mensagem. Por favor tente mais tarde..")</script>'; exit ($refresh); } } else{ echo '<script type="text/javascript">alert("Por favor preencha todos os campos.")</script>'; exit ($refresh); } ?> <!-- content --> <div id="content"> <div class="indent"> <p class="p1"> <font size="3"> Aqui poderá expôr as suas dúvidas ou comentários. <br> Coloque o seu E-Mail correcto, para podermos responder o mais breve possível. </font> </p> <form id="contacts-form" action=""> <div class="field"><label>Nome: </label><input type="text" name="nome" value=""/> </div> <div class="field"><label>E-mail: </label><input type="text" name="email" value=""/> </div> <div class="field"><label>Messagem: </label><textarea cols="3" rows="4" name="mensagem" value=""></textarea></div> <input type="submit" value="Enviar" name="enviar"> <input type="Reset" value="Apagar Tudo" name="apagar"> </form> </div> </div> <?PHP include 'rodape.php'; ?> This is what i got, if someone can help... PLEASE!!! Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/ Share on other sites More sharing options...
Pikachu2000 Posted August 30, 2011 Share Posted August 30, 2011 You've neglected to mention what the problem actually is. Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263721 Share on other sites More sharing options...
PF2G Posted August 30, 2011 Author Share Posted August 30, 2011 Oops, sorry. The problem is that i can't recieve the email. I checked the Spam...and i got nothing. Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263726 Share on other sites More sharing options...
Pikachu2000 Posted August 30, 2011 Share Posted August 30, 2011 The From: header should contain an email address that's valid on your server, not the email address submitted in the form. When you submit the form, which JS alert did you get, the "contato enviado" message, or the "Problema" message? Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263729 Share on other sites More sharing options...
PF2G Posted August 31, 2011 Author Share Posted August 31, 2011 In that "Form:", the $email is where the user says his email, it isn't the same email everytime. The problem is in line 6: if (!filter_var($email, FILTER_VALIDATE_EMAIL)) Because as soon as i open the 'contact.php' page and appears "Email inválido!. (line 8 - "echo '<script type="text/javascript">alert("E-mail inválido!.")</script>';"). Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263978 Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2011 Share Posted August 31, 2011 I know that, and that is exactly what it should not be. As I said, the From: header should be set to an email address that is valid on the server. If your plan is to be able to use the 'Reply' button in your mail client to reply to the email address that was sent in the form, then you need to add a Reply-to: header set to that address. Now on to the current problem. As far as I can tell, you have no logic in place to check if the form has actually been submitted before you start validating fields. When the form loads, the $email variable is non-existent, thus failing the validation and causing the JS alert. If you have error_reporting() set to an appropriate value for developing, you should be getting at least one 'Undefined Variable' notice. Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263996 Share on other sites More sharing options...
PF2G Posted August 31, 2011 Author Share Posted August 31, 2011 I know that, and that is exactly what it should not be. As I said, the From: header should be set to an email address that is valid on the server. If your plan is to be able to use the 'Reply' button in your mail client to reply to the email address that was sent in the form, then you need to add a Reply-to: header set to that address. Now on to the current problem. As far as I can tell, you have no logic in place to check if the form has actually been submitted before you start validating fields. When the form loads, the $email variable is non-existent, thus failing the validation and causing the JS alert. If you have error_reporting() set to an appropriate value for developing, you should be getting at least one 'Undefined Variable' notice. And i have a notice about line 6: if (!filter_var($email, FILTER_VALIDATE_EMAIL)) i've been told that makes more sense if the FILTER_SANITIZE_EMAIL stays before FILTER_VALIDATE_EMAIL. But i get the same problem. Look if you have a better and easier way, share it please. Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1264010 Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2011 Share Posted August 31, 2011 Did you read the second paragraph? In it, I told you what the problem is. The second sentence of it is of particular relevance to your situation. Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1264022 Share on other sites More sharing options...
PF2G Posted September 23, 2011 Author Share Posted September 23, 2011 After several day of hard work i now can send email But message doen't show if (isset($_REQUEST['email'])) { //send email $to = 'paulo.devil92@gmail.com' ; $subject = "Dúvida/Comentário Escola Música VNG" ; $email = $_REQUEST['email'] ; $nome = $_REQUEST['nome'] ; $msg = $_REQUEST['mensagem'] ; if (mail($to, $subject, "From: " . $nome, $email, $msg)) { echo "Mensagem enviada com sucesso. Obriagado!!"; header("Location: http://escolamusicavng.net16.net/contact.php"); } else { echo "Envio falhado. Tente mais tarde."; } } Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1272174 Share on other sites More sharing options...
Pikachu2000 Posted September 23, 2011 Share Posted September 23, 2011 You have the arguments in the wrong order in the call to mail. mail( $to, $subject, $message, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1272176 Share on other sites More sharing options...
PF2G Posted October 15, 2011 Author Share Posted October 15, 2011 Thank you. Thanks to you my problem is solved. Quote Link to comment https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1279617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.