Jump to content

Recommended Posts

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!!!

Link to comment
https://forums.phpfreaks.com/topic/246067-send-e-mail-php/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263729
Share on other sites

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>';").

Link to comment
https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263978
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1263996
Share on other sites

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. ;)

Link to comment
https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1264010
Share on other sites

  • 4 weeks later...

After several day of hard work i now can send email  8)

 

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.";
} 
}

Link to comment
https://forums.phpfreaks.com/topic/246067-send-e-mail-php/#findComment-1272174
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.