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?