Send mail with data of a form [duplicate]

1

I have a form in a html file and needed to click on submit > the data was sent to a mail. I've tried putting it in form , action="mailto: ...." , which was the only solution I found, but when I clicked on submit > just went to Outlook. Does anyone know how to do that when submitting the data would be sent to an email?

<form action="php/mail.php" method="POST" accept-charset="utf-8"> 
  <input type="text" id="nome" name="nome" placeholder="Nome"  required> 
  <input type="email" id="mail" name="email" placeholder="E-mail"  required>
  <textarea id="message" name="mensagem" placeholder="Mensagem"required></textarea>
  <button class="btn btn-primary" type="reset">Apagar</button>
  <button class="btn btn-primary" type="submit">Enviar</button>
</form>
    
asked by anonymous 02.07.2015 / 16:44

3 answers

0

So friend, the easiest way is to use a dynamic php language, asp, .net, plus some factors are also very crucial the host where your site is hosted because this influences a lot because each host has its configuration for sending of e-mail. more on google you will find several tutorials about this: look at this example link any questions posed your doubt. hug.

    
02.07.2015 / 17:36
0

Bruno , you should ideally use PHPMailer (in PHP ). It's famous, fairly discussed here in Stackoverflow and super simple to implement.

Just create a file (eg phpmailer_enviar.php ) and import the class using require_once("phpmailer/class.phpmailer.php"); the content received from the form in the body of the message in $mail->Body . Remember that this file should action='phpmailer_enviar' .

<?php
// Inclui o arquivo class.phpmailer.php localizado na pasta phpmailer
require_once("phpmailer/class.phpmailer.php");

// Inicia a classe PHPMailer
$mail = new PHPMailer();

// (...)

See a complete tutorial at: link

    
02.07.2015 / 17:37
0

HTML has no native function for automatic email sending because it is client side . What mailto does at most is just open the email client with form information.

As I said in the comment, to do this you can use the PHP mail function (which is server side ), as follows:

First you create variables to store values coming from form , using the $_POST superglobal.

For example, if the input field looks like this:

<input type="text" name="nome">
<input type="text" name="endereco">
<input type="email" name="email">

The variables in PHP will look like this:

<?php

$nome = $_POST['nome'];
$email = $_POST['email'];
$endereco = $_POST['endereco'];

?>

Then, you create the variables that the mail function PHP will use to send the email: $to , $subject , $msg :

$to = "[email protected]";
$subject = "O assunto";
$msg = "Nome: $nome \n Endereço: $endereco."; // aqui você pode incluir os campos que quiser

Then you call the function mail :

mail($to, $subject, $msg);

Then, we will create the file enviaremail.php (edit: I edited based on your HTML, test and if problem occurs let me know):

<html>
<head> 
<title>Página de Enviar e-mail </title>
</head>
<body>
<?php

$nome = $_POST['nome']; // o $_POST usa o name pra pegar os dados
$email = $_POST['email'];
$mensagem = $_POST['mensagem'];

$to = "[email protected]";
$subject = "O assunto";
$msg = "Nome: $nome\n" . // O \n pula uma linha e o . conecta os pedaços
"Mensagem: $mensagem\n" .
"Enviado por: $email"; 
// aqui você pode incluir os campos que quiser
mail($to, $subject, $msg);

echo "Obrigado por enviar seu email"; // esta será a mensagem na página de saída, depois do e-mail ser enviado, mas vc pode personalizar...

?>
</body>
</html>

Then in the HTML page you call the created file:

<form method="post" action="enviaremail.php">

This should generate output like this at [email protected]:

  

Name: [The name you typed in the form]; Home   Address: [The address entered on the form];
  Posted by: [typed email form];

Note: If you are just wanting to send from localhost is already a bit more complicated, but there is the answer here in SOpt: How to send localhost email using the PHP mail function?

    
02.07.2015 / 17:52