Hola como estas? Te agradezco tu interés en ayudarme.
Este es el formulario original que tengo en una plantilla html5, a este lo tengo en la sección contacto de mi web.
------------------------------------------------------------------------------------------------------------------------------------
<script type="text/javascript" src="js/form-validation.js"></script>
<form id="contactForm" action="#" method="post">
<fieldset>
<p>
<label for="name" >Nombre y apellido</label>
<input name="name" id="name" type="text" class="form-poshytip" title="Ingresa tu nombre y apellido" />
</p>
<p>
<label for="email" >Email</label>
<input name="email" id="email" type="text" class="form-poshytip" title="Ingresa tu email" />
</p>
<p>
<label for="comments">Mensaje</label>
<textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Ingresa algún mensaje"></textarea>
</p>
<!-- send mail configuration -->
<input type="hidden" value="
[email protected]" name="to" id="to" />
<input type="hidden" value="Consulta página web" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" value="Envíar" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">Datos envíados. Muchas gracias por comunicarse.</p>
<!-- ENDS form -->
----------------------------------------------------------------------------------------------------------------------------------------------------------
Acá te paso el archivo php que funciona bien con este formulario.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['email'];
//data
$msg = "NOMBRE: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "COMENTARIOS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Este funciona perfectamente, lo que hice fue utilizar el mismo formulario, cambiar los campos para otra sección porque necesito mas información. Ahora te paso el formulario cambiado y el archivo php modificado.
------------------------------------------------------------------------------------------------------------------------------------------------------------
<script type="text/javascript" src="js/form-validation.js"></script>
<form id="contactForm" action="#" method="post">
<fieldset>
<p>
<label for="name" >Nombre y apellido</label>
<input name="name" id="name" type="text" class="form-poshytip" title="Ingresa tu nombre y apellido" />
</p>
<p>
<label for="email" >Email</label>
<input name="email" id="email" type="text" class="form-poshytip" title="Ingresa tu email" />
</p>
<p>
<label for="telefono" >Teléfono</label>
<input name="telefono" id="telefono" type="text" class="form-poshytip" title="Ingresa tu teléfono" />
</p>
<p>
<label for="DNI" >DNI</label>
<input name="DNI" id="DNI" type="text" class="form-poshytip" title="Ingresa tu DNI" />
</p>
<p>
<label for="direccion" >Dirección</label>
<input name="direccion" id="direccion" type="text" class="form-poshytip" title="Ingresa tu dirección" />
</p>
<!-- send mail configuration -->
<input type="hidden" value="
[email protected]" name="to" id="to" />
<input type="hidden" value="" name="Datos curso operador" id="subject" />
<input type="hidden" value="send-mailcurso.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" value="Envíar" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">Registrado exitosamente. Para asegurar tu lugar debes inscribirte. <br><br>
<br>
MODULO 1 - TELEFONISTA DE EMERGENCIAS<br><br>
<a href="https://www.mercadopago.com/mla/checkout/pay?pref_id=176651461-bb38f322-706f-4e8c-86dc-78359a16692e" target="new" class="link-button">Abonar inscripcion</a> <a href= "https://www.mercadopago.com/mla/checkout/pay?pref_id=176651461-ea60e17e-c5d5-4b15-a7e3-31b2be51b80c" class="link-button" target="new">Abonar curso</a><br><br><br>
</p>
<!-- ENDS form -->
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Este es el formulario cambiado, lo que hice fue borrar el campo message, y agregar los campos direccion, dni y telefono. Ahora en el php que modifique lo que hice es borrar comments y agregar los id de los otros campos para que me los envíe por mail. te muestro el archivo php modificado.
---------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['email'];
//data
$msg = "NOMBRE: ".$_POST['name'] ."<br>\n";
$msg .= "EMAIL: ".$_POST['email'] ."<br>\n";
$msg .= "TELEFONO: ".$_POST['telefono'] ."<br>\n";
$msg .= "DNI " .$_POST['DNI'] ."<br>\n";
$msg .= "DIRECCIÓN: ".$_POST['direccion'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Cuando envía el mail, la información que se carga en mail y name las manda perfectamente. Pero a los campos que modifique (dni , telefono y direccion) no los envía. Queda un espacio en blanco, si me pudieras ayudar a ver donde esta el error te lo agradeceria. Saludos.