Ver Mensaje Individual
  #10 (permalink)  
Antiguo 09/03/2008, 10:31
opzina
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Formulario autorespuesta

<?
/**
* - sending mail via form
*
* Author: Alex Scott
* Details: The installation file
* Release: 1.1 ($Revision: 1.6 $)
*
* A U T O R E S P O N D E D O R
*
*/

/************************************************** ***************************
* *
* C O N F I G U R A C I O N *
* *
************************************************** ***************************/

// MODIFICA TU EMAIL AQUÍ //////////////////////////////////////////
// si está vació usará el email del campo ('send_to')
$send_to = "<[email protected]>";

// Configura $send_cc si deseas enviar otra copia de la orden de hosting a otro email
// por ejemplo: $send_cc = array('O.COM'');
$send_cc = array('[email protected]', '[email protected]');

// MODIFICA AQUÍ el Subject o Título del email que recibirás en tu correo
// Puedes modificarlo si deseas recibirlo con otro nombre
$subject = "Consulta desde Sitio web ";

// No modificar
$referrers = array();

// No modificar - Si deseas puedes incluir el envio de archivos, valor 1 si, 0 no.
$attachment_enabled = 0;

// No modificar - Database - write CSV file with data of submitted forms //////////////
$database_enabled = 0;
$database_file = 'email.csv';

// Fields to collect
// $database_fields = '*' - mean all fields, as in form
// $database_fields = array('from', 'subject') - only 'from', 'subject' fields
$database_fields = '*';

//////MODIFICA AQUÍ Dirección URL después de procesar el formulario
$redirect_url = 'http://www.tu-pagina-web.com/contacto-enviado-ok.html';

////// AutoRespondedor
////// Puedes cambiar cualquiera de los campos usando...
////// %nombre_campo% en el email de respuesta.
//////
$autoresponder_enabled = 1;
$autoresponder_from = $send_to;
$autoresponder_subject = "Tu Mensaje ha Sido recibido ";
$autoresponder_message = <<<MSG

%nombre_req%:

Tu pregunta o comentario ha sido recibido

Te responderé en breve plazo.

Muchas Gracias.

http://www.tu-pagina-web.com/

___________________
Tu mensaje fué:
%comentarios%



----------------------------------------------------------------------------


MSG;

/************************************************** *************************/

function do_formmail(){
global $autoresponder_enabled, $database_enabled;
$form = get_form_data();
$errors = check_form($form);
if ($errors) {
display_errors($errors);
return;
}
send_mail($form);
if ($autoresponder_enabled)
auto_respond($form);
if ($database_enabled)
save_form($form);
redirect();
}

function redirect(){
global $redirect_url;
header("Location: $redirect_url");
exit();
}


function save_form($vars){
global $database_file, $database_fields;
$f = fopen($database_file, 'a');
if (!$f){
die("Cannot open db file for save");
}
foreach ($vars as $k=>$v) {
$vars[$k] = str_replace(array("|", "\r","\n"), array('_',' ',' '), $v);
}
if (is_array($database_fields)) {
$vars_orig = $vars;
$vars = array();
foreach ($database_fields as $k)
$vars[$k] = $vars_orig[$k];
}
$str = join('|', $vars);
fwrite($f, $str."\n");
fclose($f);
}

function auto_respond($vars){
global $autoresponder_from, $autoresponder_message, $autoresponder_subject;
/// replace all vars in message
$msg = $autoresponder_message;
preg_match_all('/%(.+?)%/', $msg, $out);
$s_vars = $out[1]; //field list to substitute
foreach ($s_vars as $k)
$msg = str_replace("%$k%", $vars[$k], $msg);
/// replace all vars in subject
$subj = $autoresponder_subject;
preg_match_all('/%(.+?)%/', $subj, $out);
$s_vars = $out[1]; //field list to substitute
foreach ($s_vars as $k)
$subj = str_replace("%$k%", $vars[$k], $subj);
//
$_send_to = "$vars[name_from] <".$vars[email_from].">";
$_send_from = $autoresponder_from;
mail($_send_to, $subj, $msg, "From: $_send_from");
}

function _build_fields($vars){
$skip_fields = array(
'name_from',
'email_from',
'email_to',
'name_to',
'subject');
// order by numeric begin, if it exists
$is_ordered = 0;
foreach ($vars as $k=>$v)
if (in_array($k, $skip_fields)) unset($vars[$k]);

$new_vars = array();
foreach ($vars as $k=>$v){
// remove _num, _reqnum, _req from end of field names
$k = preg_replace('/_(req|num|reqnum)$/', '', $k);
// check if the fields is ordered
if (preg_match('/^\d+[ \:_-]/', $k)) $is_ordered++;
//remove number from begin of fields
$k = preg_replace('/^\d+[ \:_-]/', '', $k);
$new_vars[$k] = $v;
}
$vars = $new_vars;

$max_length = 10; // max length of key field
foreach ($vars as $k=>$v) {
$klen = strlen($k);
if (($klen > $max_length) && ($klen < 40))
$max_length = $klen;
}

if ($is_ordered)
ksort($vars);

// make output text
$out = "";
foreach ($vars as $k=>$v){
$k = str_replace('_', ' ', $k);
$k = ucfirst($k);
$len_diff = $max_length - strlen($k);
if ($len_diff > 0)
$fill = str_repeat('.', $len_diff);
else
$fill = '';
$out .= $k."$fill...: $v\n";
}
return $out;
}


function send_mail($vars){
global $send_to, $send_cc;
global $subject;
global $attachment_enabled;
global $REMOTE_ADDR;

global $HTTP_POST_FILES;
$files = array(); //files (field names) to attach in mail
if (count($HTTP_POST_FILES) && $attachment_enabled){
$files = array_keys($HTTP_POST_FILES);
}


continua en el post siquiente