Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/11/2011, 17:29
zido45
 
Fecha de Ingreso: noviembre-2011
Ubicación: madrid
Mensajes: 30
Antigüedad: 12 años, 5 meses
Puntos: 0
Enviar formulario a email

hola buenas tengo una web un formulario html mediante el cual quiero enviar esos datos que rellenes al correo/email pero no soy capaz
tengo los siguientes codigo.


<!-- Contact Form -->
<form action='send_email1.php' method='post' id='contact_form'>
<h3>Formulario de contacto.</h3>
<div class="hr dotted clearfix">&nbsp;</div>
<ul>
<li class="clearfix">
<label for="name">Nombre/Name</label>
<input type='text' name='name' id='name' />
<div class="clear"></div>
<p id='name_error' class='error'>Insert a Name</p>
</li>
<li class="clearfix">
<label for="email">Email</label>
<input type='text' name='email' id='email' />
<div class="clear"></div>
<p id='email_error' class='error'>Enter a valid email address</p>
</li>
<li class="clearfix">
<label for="subject">Título/Subject</label>
<input type='text' name='subject' id='subject' />
<div class="clear"></div>
<p id='subject_error' class='error'>Enter a message subject</p>
</li>
<li class="clearfix">
<label for="message"> Mensaje/Message</label>
<textarea name='message' id='message' rows="30" cols="30"></textarea>
<div class="clear"></div>
<p id='message_error' class='error'>Enter a message</p>
</li>
<li class="clearfix">

<p id='mail_success' class='success'>Thank you. I'll get back to you as soon as possible.</p>
<p id='mail_fail' class='error'>Sorry, an error has occured. Please try again later.</p>
<div id="button">
<input type='submit' id='send_message' class="button" value='Enviar' />
</div>
</li>
</ul>
</form>
</div>

y en ese archivo send_email.php tengo esto.

<?php
//we need to get our variables first

include 'config.php'; // aqui tengo mi direccion de correo
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

/*the $header variable is for the additional headers in the mail function,
we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
That way when we want to reply the email gmail(or yahoo or hotmail...) will know
who are we replying to. */
$headers = "From: $email\r\n";
$headers .= "Reply-To:$email\r\n

if(mail($email_to, $subject, $message, $headers)){
echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..

}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
?>