Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2013-05-26 22:34:18
- gfdesign
- Member
- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Troubles with PHP code in TXP (Contact form with attachment files)
Dears
I got a PHP script for a contact form with the feature to attach files (because, as you know it is not possible to do it using zem_contact_reborn). This works like a charm in TXP 4.4.1, but when I updated my site to TXP 4.5.2 this code has stopped working. I mean, this form works perfectly in TXP 4.4.1 but doesn’t in 4.5.2, even using <txp:php> tags
below, I put the code of the form I was using in case be useful to somebody or if there is anybody can help me it works on TXP 4.5.2
(Note: This form requires class.phpmailer.php and jquery.MultiFile.pack.js)
<?php
/*
NOTE:
this file must be with a folder called "archivos" where files will be copied. This folder must be chmod 777
*/
//CONFIGURATION
$direccion_envio='name@domain.com'; //destination email
$url= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
//URL where form will be published. Slash at the end shouldn't be.
$cantidad_archivos=1;
//Max files is allowed to send.
//END CONFIGURATION
?>
<?php
//form process
// if it exists, so "enviar" (send) ...
if (isset ($_POST['enviar'])) {
// we need to use phpmailer class,
require("class.phpmailer.php");
$mail = new PHPMailer();
//we take the variables and set up PHPMailer
$mail->From = $_POST['email'];
$mail->FromName = $_POST['nombre'];
$mail->AddAddress($direccion_envio);
$mail->Subject = "Title of subject";
$mail->AddReplyTo($_POST['email'],$_POST['nombre']);
$mail->IsHTML(true);
$comentario=$_POST['comentario'];
//we check if files are attached, we copy to server and we send as attachment in the email
if (isset($_FILES['archivo']['tmp_name'])) {
$achivos_adjuntos='';
$i=0;
do {
if($_FILES['archivo']['tmp_name'][$i] !="")
{
$aleatorio = rand();
$nuevonombre = $aleatorio.'-'.$_FILES['archivo']['name'][$i];
copy($_FILES['archivo']['tmp_name'][$i],'archivos/'.$nuevonombre);
$achivos_adjuntos .= '<br /><a href="'.$url.'/archivos/'.$nuevonombre.'">'.$nuevonombre.'</a></strong>';
$mail->AddAttachment($_FILES['archivo']['tmp_name'][$i], $nuevonombre);
}
$i++;
} while ($i < $cantidad_archivos);
}
//we check if all files are completed
if ($_POST['email']!='') {
$email=$_POST['email'];
$nombre=$_POST['nombre'];
$apellido=$_POST['apellido'];
$comentario=$_POST['comentario'];
$user_ip = $_SERVER['REMOTE_ADDR'];
//we create the html
$contenido = '<html><body>';
$contenido .= '<p>Enviado el '. date("d M Y").'</p>';
$contenido .= '<hr />';
$contenido .= '<p>Nombre: <strong>'.$nombre.'</strong></p>';
$contenido .= '<p>Apellido: <strong>'.$apellido.'</strong></p>';
$contenido .= '<p>Email: <strong>'.$email.'</strong></p>';
$contenido .= '<p>Comentario: <strong>'.$comentario.'</strong></p>';
$contenido .= '<hr />';
$contenido .= '<p>Archivos Adjuntos: '.$achivos_adjuntos.'</p>';
$contenido .= '<hr />';
$contenido .= '</body></html>';
$mail->Body = $contenido;
// if all field were completed, we send the mail
$mail->Send();
$flag='ok';
$mensaje='<div id="ok">SU MENSJAE FUE ENVIADO CORRECTAMENTE</div>';
} else {
//if all fields weren't completed, we stop the send and notify to user
$flag='err';
$mensaje='<div id="error">- Los Campos Marcados Con * Son Requeridos. '.$error_archivo.'</div>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="<txp:site_url/>js/jquery.MultiFile.pack.js" type="text/javascript" language="javascript"></script>
</head>
<body>
<div class="contact-form">
<?php echo $mensaje; /*we show the status of mailing form*/ ?>
<?php if ($cantidad_archivos > 1) {$plural='s';} else {$plural='';} ?>
<?php if ($flag!='ok') { ?>
<form id="formInscripcion" action="<?php echo $PHP_SELF;?>" method="post" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="nombre_campo" >Nombre:*</td>
<td><label>nombre</label>
<input name="nombre" type="text" id="nombre" size="50" /></td>
</tr>
<tr>
<td class="nombre_campo">Apellido:*</td>
<td><input name="apellido" type="text" id="apellido" size="50" /></td>
</tr>
<tr>
<td class="nombre_campo">E-mail:*</td>
<td><input name="email" type="text" id="email" size="50" /></td>
</tr>
<tr>
<td class="nombre_campo">Adjunte aquí su archivo:<br><span style="font-size:8px">Max. 2 Mb</span></td>
<td>Puede adjuntar hasta <?=$cantidad_archivos?> archivo<?=$plural?>
<input type="file" class="multi max-<?=$cantidad_archivos?>" name="archivo[]" value="<?=$_FILES['archivos']?>">
</td>
</tr>
<tr>
<td valign="top" class="nombre_campo" style="vertical-align:top; padding-top:15px" >Su Consulta:</td>
<td><textarea cols="45" rows="10" name="comentario"></textarea></td>
</tr>
<tr>
<td style="text-align:center;" colspan="2" >
<button type="reset" class="form_btenviar">BORRAR</button>
<button type="submit" class="form_btenviar" name="enviar">ENVIAR</button>
</td>
</tr>
</table>
</form>
<?php } ?>
</div><!-- fin "contact-form" -->
</body>
</html>
Offline