formulario en .html
Código HTML:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Formulario email</title> <style type="text/css"> <!-- .Estilo1 { color: #999999; font-weight: bold; } --> </style> </head> <body bgcolor="#372f2d"> <table align="center" valign="middle" width="680" border="1" cellpadding="10" cellspacing="0" bordercolor="#999999"> <tr> <td height="206" align="center"><form method="post" action="direccion de hosting mail.php"> //modificado <input type="hidden" name="to" value="micorreo" /> //modificado <input type="hidden" name="return_url_ok" value="direccion de correo enviado" /> //modificado <input type="hidden" name="return_url_ko" value="direccion de correo no enviado" /> //modificado <table width="630" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="150"><span class="Estilo1">Tipo de consulta: </span></td> <td width="510"><input name="tema" type="text" size="55" /></td> </tr> <tr> <td><span class="Estilo1">Nombre y apellidos:</span></td> <td><input name="nombre" type="text" size="55" /></td> </tr> <tr> <td><span class="Estilo1">E-mail:</span></td> <td><input name="email" type="text" size="55" /></td> </tr> <tr> <td><span class="Estilo1">Teléfono:</span></td> <td><input id="telefono" name="telefono" type="text" size="30" /></td> </tr> <tr> <td valign="top"><span class="Estilo1">Consulta:</span></td> <td><textarea id="comentario" name="comentario" cols="53" rows="3" ></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="send" value="Enviar" /></td> </tr> </table> </form></td> </tr> </table> </body> </html>
Código PHP:
<?php
/************CONFIGURACIÓN**************/
$email_de_destino="micorreo"; //modificado
$campo_email_origen="email";
/***********************************************/
function ValidarDatos($campo){
//Array con las posibles cabeceras a utilizar por un spammer
$badHeads = array("Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"Return-path:",
"Subject:",
"From:",
"Envelope-to:",
"To:",
"bcc:",
"cc:");
foreach($badHeads as $valor)
{
if(strpos(strtolower($campo), strtolower($valor)) !== false)
{
header("HTTP/1.0 403 Forbidden");
exit;
}
}
}
foreach($_POST as $key=>$value)
{
ValidarDatos($value);
$mail .=strtoupper(substr($key,0,1)).strtolower(substr($key,1,strlen($key)))." : ".$value."\n";
}
mail($email_de_destino,"Consulta desde la web",$mail,"From: ".$_POST[$campo_email_origen]);
?>
<html>
<head><title>Consulta enviada</title>
<style type="text/css">
<!--
.Estilo1 {color: #999999}
-->
</style>
</head>
<body bgcolor="#372f2d">
<table width="100%" height="100%">
<tr>
<td width="100%" height="100%" valign="middle" align="center">
<span class="Estilo1">Su petición ha sido mandada con exito<br />
En breve nos pondremos en contacto con usted </span></td>
</tr>
</table>
</body>
</html>
Código PHP:
<?php
//-----------------Getting data sent by flash---------------------
foreach ($_POST as $key => $value){
if ($key != 'mail_to' && $key != 'smtp_server' && $key != 'smtp_port' && $key != 'mail_from' && $key != 'mail_subject' && $key != 'plain_text'){
$mail_body .= '<b>'.str_replace('_',' ',$key).'</b>:<br/>';
$mail_body .= ''.stripslashes($value).'<br/>';
}
}
//-----------------------------------------------------------------
$message = '<html><body>'.$mail_body.'</body></html>'; // mail body
//------------if plain text is set to true removing html tags------
if ($_POST['plain_text']=='true') {
$message = str_replace('<br/>',"\r\n", $message);
$message = strip_tags($message);
//------------------------------------------------------------------
} else {
//----otherwise composing message headers---------------------------
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//------------------------------------------------------------------
}
//------------setting conf data-------------------------------------
$to = $_POST['mail_to'];
$from = $_POST['mail_from'];
$subject = $_POST['mail_subject'];
$smtp_server = $_POST['smtp_server'];
$smtp_port = $_POST['smtp_port'];
//------------------------------------------------------------------
//---------setting header info--------------------------------------
$headers .= 'To: '.$to. "\r\n";
$headers .= 'From: Site visitor ' .$from. "\r\n";
//------------------------------------------------------------------
if (mail($to, $subject, $message, $headers)){ // sending mail
print('&mail=1'); //succes
} else {
print('&mail=0');//failure
}
?>
Código HTML:
<?xml version="1.0" encoding="utf-8"?> <contactFormConfiguration> <emailTo>micorreo</emailTo> //modificado <serverProcessorType>php</serverProcessorType> <serverProcessorFileName>contac</serverProcessorFileName> <validateRequiredOnly>false</validateRequiredOnly> <submitFormOnEnter>false</submitFormOnEnter> <messageSentText>Gracias por su mensaje.</messageSentText> < <messageSentFailedText>Gracias por su mensaje.</messageSentFailedText> <formProcessingText>Cargando...</formProcessingText> <smtpServer>localhost</smtpServer> <smtpPort>25</smtpPort> <plainText>false</plainText> <emailFromSource>3</emailFromSource> <subjectSource>Correo desde web</subjectSource>
Gracias.
Un saludo.