How to send email with PHP?
I have a website under construction that people have the possibility to enter an email, I would like that as soon as they enter their email and click the "Subscribe" Button, an auto-reply email would be sent to them, how could I do that?
9
Author: Daniel Omine, 2014-07-05
2 answers
Take a look at PHP's mail function. If you are using a standard hosting it must be pre-configured.
With the function mail
working, you simply create an HTML form to perform this action.
A basic example of using
Index.html
<form method="post" name="meu-form" action="send-mail.php">
Nome: <input type="text" name="nome">
Email: <input type="text" name="email">
Mensagem: <textarea name="mensagem"></textarea>
<input type="submit" value="Enviar">
</form>
Send email.php
<?php
$nome = $_POST['nome'];
$email= $_POST['email'];
$mensagem= $_POST['mensagem'];
$to = "[email protected]";
$assunto = "Mensagem de ".$email.com
mail($to,$assunto,$mensagem);
?>
9
Author: Guilherme Tonioli, 2014-07-05 23:46:01
Another way to send the data is as follows:
<?php
//Variáveis que recebem os dados digitados no formulário pelo id atribuído nos input
$nome = $POST[nome];
$email = $POST[email];
$assunto = $POST[assunto];
$mensagem = $POST[mensagem];
mail (
"[email protected]", //Endereço que vai receber a mensagem
"Nome: $nome
Email: $email
Assunto: $assunto
Mensagem: $mensagem", "FROM:$nome<$email>");
?>
I'm not a programmer, but this way is not so secure I think because in others it has data verification to prevent the user from sending malicious data by the form. But it works normal.
-1
Author: Beto Pereira, 2018-06-14 22:38:16