Submission of forms to an email [closed]

0

Hello, I want you to fill in the form that I put on my page, the e-mails come to my personal email, this is the code of my form, it is in html

  <div class="grid_6 preffix_1">
    <h2>Envianos tu mensaje</h2>
          <form id="contact-form">
              <div class="contact-form-loader"></div>
              <fieldset>
                <label class="name" title="Nombre">
                  <input type="text" name="name" placeholder="Nombre:" value="" data-constraints="@Required @JustLetters"  />
                  <span class="empty-message">*Ingresa tu nombre</span>
                  <span class="error-message">*Caracter no valido.</span>
                </label>

                <label class="email" title="E-mail">
                  <input type="text" name="email" placeholder="E-mail:" value="" data-constraints="@Required @Email" />
                  <span class="empty-message">*Ingresa correctamente tu Email.</span>
                  <span class="error-message">*Caracter no valido.</span>
                </label>
                <label class="phone" title="Celular">
                  <input type="text" name="phone" placeholder="Celular:" value="" data-constraints="@Required @JustNumbers" />
                  <span class="empty-message">*Ingresar numero celular</span>
                  <span class="error-message">*Caracter no valido.</span>
                </label>

                <label class="message" title="Mensaje">
                  <textarea name="message" placeholder="Mensaje:" data-constraints='@Required @Length(min=20,max=999999)'></textarea>
                  <span class="empty-message">*Es necesario llenar este espacio</span>
                  <span class="error-message">*Mensaje muy corto.</span>
                </label>
                <div class="ta__right">
                  <a href="#" class="btn" title="Limpiar" data-type="reset">Limpiar</a>
                  <a href="#" class="btn" title="Enviar"data-type="submit">Enviar</a>
                </div>
              </fieldset> 
              <div class="modal fade response-message">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                      <h4 class="modal-title">¡Listo!</h4>
                    </div>
                    <div class="modal-body">
                      Tu mensaje se envio exitosamente.
                    </div>      
                  </div>
                </div>
              </div>
            </form>   
  </div>

*. php

<?php
error_reporting(0);
$nombre = $_POST['nombre'];
$correo_electronico= $_POST['email'];
$poblacion = $_POST['poblacion'];
$sexo=$_POST['GrupoOpciones1'];
$aficiones=$_POST['comentarios'];
$radio= $_POST['GrupoOpciones2'];
$opinion=$_POST['opinion'];
$header = 'From: ' . $mail . ", de la poblacion ".$poblacion."\r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";

$mensaje = "Este mensaje fue enviado por " . $nombre . " \r\n";
$mensaje .= "Su e-mail es: " . $mail . " \r\n";
$mensaje .= "sexo" . $_POST['GrupoOpciones1'] . " \r\n";
$mensaje .= "aficiones " . $_POST['comentarios'] . " \r\n";
$mensaje .= "que opinas de nuestra pagina" . $_POST['GrupoOpciones2'] . " \r\n";
$mensaje .="danos tu opinion".$_POST['opinion'] . " \r\n";
$mensaje .= "Enviado el " . date('d/m/Y', time());

$para = 'AQUÍ PONES TU CORREO';
$asunto = 'AQUÍ LO QUE QUIERAS';

mail($para, $asunto, utf8_decode($mensaje), $header);

echo 'mensaje enviado correctamente';

?> 
    
asked by Raul Simon 20.11.2017 в 22:05
source

2 answers

1

To use the php mail function you must configure the smtp in the php.ini. Depending on where you are hosting your site, you may not have access to this file.

You can use a library to send the mail instead of the mail function, since it will be easier to configure the SMTP. Like this library below:

$mail = new PHPMailer(true); 
$mail->isSMTP();  
$mail->Host = 'smtp1.example.com;'; //el host del smtp que vas a utilizar
$mail->SMTPAuth = true;                             
$mail->Username = '[email protected]';  // El usuario del smtp
$mail->Password = 'secret';            // La contraseña del usuario del smtp
$mail->SMTPSecure = 'tls';            
$mail->Port = 587; //El puerto que vas a utilizar para conectarte al smtp                                   

//Correos a los que se envia
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User');

//Contenido
$mail->isHTML(true); 
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';

$mail->send();

More information from the library in the following link: PHPMailer

    
answered by 20.11.2017 / 23:06
source
0

The first thing you should know is that from the "pure" HTML you can not send emails ...

You can do as they say using a simple program written in PHP that returns the form data to your email. The first thing you can write is a file (for example, name info.php) with the following code:

<?php
  phpinfo();
?>

Read it from the browser (and so we see the version of PHP that you have and if it is working)

From there we can help you ... Even with 3 simple PHP lines, but you have to know if you have PHP installed correctly and it works for you!

If you have everything correctly working, simplifying is the following:

formular.html

...
<form id="email" name="email" method="post" action="email.php">
 <input id="uno" name="uno" type="...">
 <input id="dos" name="dos" type="...">
 ...
 <button type="submit">enviar email</button>
</form>
...

The "PHP program" (email.php) is as simple as the one you were put on top of ... Simplifying it:

<?php
 $destino = "[email protected]";
 $asunto = "....."; // Lo puedes poner fijo o recibirlo desde el form
 $v1 = $_POST['uno'];
 $v2 = $_POST['dos'];
 ...
 $mensaje = " ..." . "\n" . $v1 . "\n" . $v2 . "\n";
 mail($destino, $asunto, $mensaje);
?>
    
answered by 20.11.2017 в 23:32