9
I have a site under construction that people have the possibility to insert an email, I would like as soon as they insert their email and click on the "sign up" button, be sent an automatic reply email to them, how could do this?
9
I have a site under construction that people have the possibility to insert an email, I would like as soon as they insert their email and click on the "sign up" button, be sent an automatic reply email to them, how could do this?
9
Give a read on the function mail of PHP. If you are using a default hosting it must be preset.
With the function mail
working, just create an HTML form to perform this action.
A basic example of use
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-mail.php
<?php
$nome = $_POST['nome'];
$email= $_POST['email'];
$mensagem= $_POST['mensagem'];
$to = "[email protected]";
$assunto = "Mensagem de ".$email.com
mail($to,$assunto,$mensagem);
?>
I wanted an example, just to understand better why I read about this function and did not understand very well.
Is that right? index.html <form action="save.php" id="form" method="post" name="form"> <input type="email" name="email" placeholder="Enter your email" id="email"/> <button id="inscription" type="Submit" value="inscription">Subscribe </button> </form> save.php <? php $email = $_POST['email']; $headers = 'From: [email protected]' . " r n" 'To: ' . $_REQUEST['email'] . " r n" $subject = 'subject'; $message = 'example message. '; mail($email, $subject, $message, $headers); ?>
I met this site today, sorry for the formatting there because I don’t know how to move right yet. But if you can see if I’m correct or not, thank you.
I believe the header using "From" and "To" does not work. But it is not necessary if it has already been configured. Otherwise, it’s all right apparently.
This "From" and "To", how to leave it preconfigured? It’s the same way as the subject and the message?
On the web server you use.
@John the header should not be translated. This loads information used by the mail server. Getting: $header = "From: [email protected]";
@gtonioli, when I use the mail here, the email goes to the junk mail, you know why?
-1
Another way to send the data is the following:
<?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 safe I think because in others has the verification of the data to prevent the user to send malicious data through the form. But it works normal.
Browser other questions tagged php html email
You are not signed in. Login or sign up in order to post.
the simple use of the mail() function does not serve?
– Daniel Omine
If you can show me how you do with some example, I’d appreciate it.
– João
I use the class phpmail it is very good by the way, see a tutorial on this link http://www.devwilliam.com.br/php/enviar-e-mails-localhost-com-php-e-phpmailer
– Willian