How to pick up a form and send it to e-mail?

Asked

Viewed 150 times

0

I need to send a form from an email, I’ve researched a lot, but nothing explains exactly what each line does, and if there has to be some server online, or if with the site to test, I’ll leave my html, here, if someone can help me, I’ll be grateful!

<form  id="form1" name="form1" method="post" action="enviarEmail.php">
  <table  width="500" border="0" align="center" cellpadding="0" cellspacing="2">
    <tr>
      <td  align="right">Nome:</td>
      <td><input  type="text" name="nome" id="nome" /></td>
    </tr>
    <tr>
      <td  align="right">Assunto:</td>
      <td><input  type="text" name="assunto" id="assunto" /></td>
    </tr>
    <tr>
      <td  align="right">Mensagem:</td>
      <td><textarea  name="mensagem" id="mensagem" cols="45" rows="5"></textarea></td>
    </tr>
    <tr>
      <td  colspan="2" align="center"><input type="submit" value="Enviar" /></td>
    </tr>
  </table>
</form>
  • 1

    What PHP code are you using? Post him on the question and specify exactly what your doubt is regarding the code, so someone can help.

  • You are contradicting yourself. Como pegar um formulário e mandar para o e-mail and Preciso enviar um formulário a partir de um email. You want to email -> form or form -> email??

  • A form for the email, as if it were a CONTACT US

2 answers

1

you have 2 options first send email directly with that line

<form action="mailto:[email protected]" method="post" enctype="text/plain">
if you want in php giving the example and just follow (first list and php the second and html the same)

<?php
if(isset($_POST['email'])) {
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "Your email subject line";
 
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
 
 
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
 
     
 
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
 
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
 
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
 
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
 
  if(strlen($error_message) > 0) {
    died($error_message);
  }
 
    $email_message = "Form details below.\n\n";
 
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
 
     
 
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 
<!-- include your own success html here -->
 
Thank you for contacting us. We will be in touch with you very soon.
 
<?php
 
}
?>
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
 <td valign="top">
  <label for="first_name">First Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="first_name" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td valign="top"">
  <label for="last_name">Last Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="last_name" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="email">Email Address *</label>
 </td>
 <td valign="top">
  <input  type="text" name="email" maxlength="80" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="telephone">Telephone Number</label>
 </td>
 <td valign="top">
  <input  type="text" name="telephone" maxlength="30" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="comments">Comments *</label>
 </td>
 <td valign="top">
  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
 </td>
</tr>
<tr>
 <td colspan="2" style="text-align:center">
  <input type="submit" value="Submit">   <a href="http://www.freecontactform.com/email_form.php">Email Form</a>
 </td>
</tr>
</table>
</form>

  • My vlwww! helped me a lot!!

-1


<form  id="form1" name="form1" method="post" action="enviarEmail.php">
  <table  width="500" border="0" align="center" cellpadding="0" cellspacing="2">
    <tr>
      <td  align="right">Nome:</td>
      <td><input  type="text" name="nome" id="nome" /></td>
    </tr>
    <tr>
      <td  align="right">Assunto:</td>
      <td><input  type="text" name="assunto" id="assunto" /></td>
    </tr>
    <tr>
      <td  align="right">Mensagem:</td>
      <td><textarea  name="mensagem" id="mensagem" cols="45" rows="5"></textarea></td>
    </tr>
    <tr>
      <td  colspan="2" align="center"><input type="submit" value="Enviar" /></td>
    </tr>
  </table>
</form>

IF ONLY THAT FORM:.

$para      = '[email protected]';
$assunto = $_POST['assunto'];
$mensagem = $_POST['mensagem'];
$cabecalho = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]';
mail($para, $assunto, $mensagem, $cabecalho);

EXTRA INFORMATION:

YOU CAN PERSONALIZE, THIS EMAIL CREATING A STANDARDIZED MESSAGE. I BELIEVE YOU ARE INTERESTED IN THIS.

<input name="nome" value="RiscadoO">
<input name="sobrenome" value="RabiscadoOooo">
<input name="endereco" value="Onde judas perdeu botas">

//caputarando dados do formulario
$nome=$_POST['nome'];
$sobrenome=$_POST['sobrenome'];
$endereço=$_POST['endereço'];
$site="seusite";
$link_ativa=rand();
//final da captura
//passando dados para o email
    $para      = '[email protected]';
    $assunto = "ATIVAÇÃO DE CADASTRO NO SISTEMA";
    $mensagem =" Olá $nome !, você recebeu esse email por ter se cadastrado no $site , informações do cadastro <br> <b> Nome completo: </b> $nome $sobrenome <b><br> Endereço:<b> $endereço. <br><> Se estas informações estiverem corretas, copie o link: $site$$link_ativa. FIQUE BEM E OBRIGADO!;

    $cabecalho = 'From: [email protected]' . "\r\n" .
        'Reply-To: [email protected]';
    mail($para, $assunto, $mensagem, $cabecalho);

So it will always be a personalized message. of course this hand has to be written in the database.

  • DAMN MY VLW HELPED ME A LOT!!! I WILL TEST

  • If that’s what you wanted, mark the answer as accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.