that send me an email whith an attachment
but two funtions have problems
this is the php code: (the two funtions are line 9 and line 59)
if i cut "$name_of_uploaded_file" then the explorer page said "Call to undefined function getuploadedfileinfo() "
please help me!
php
Code: Select all
if(isset($_POST[uploaded_file]) && $_POST[uploaded_file]!="") {
$name_of_uploaded_file="No ingreso archivo adjunto" ;
include_once('Mail.php');
include_once('mime.php');
function ComposeMail($name_of_uploaded_file){
$name = $_POST['nombre'];
$user_message = $_POST['descripcion'];
$to = "cristina.arias.ing@gmail.com";
$subject="Una nueva solicitud fue realizada";
$from = $_POST['correo'];
$ubi = $_POST['ubicacion'];
$tel = $_POST['telefono'];
$emp = $_POST['empresa'];
$text = "Haz recibido de: " . $name ."\n"."Ubicado en:".$ubi."\n"."Telefono:".$tel. "\n"."Empresa:".$emp. "\n"."Envio lo
siguiente: ".
$user_message;
$message = new Mail_mime();
$message->setTXTBody($text);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
echo "Tu solicitud de cotización fue enviada exitosamente". "\n"."A la mayor brevedad te responderemos.<a
href='index.html'>Regresar a inicio</a>";
}
}
else {
$max_allowed_file_size = "5000"; // this is size in KB
list($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file) = GetUploadedFileInfo();
if(!Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size)) {
exit();
}
LoadUploadedFile($name_of_uploaded_file);
$path_of_uploaded_file = "uploads/" . $name_of_uploaded_file;
include_once('Mail.php');
include_once('mime.php');
ComposeMail($path_of_uploaded_file);
//////////////////// Functions ////////////////////////
function GetUploadedFileInfo() {
$file_info[] = basename($_FILES['uploaded_file']['name']);
$file_info[] = substr($file_info[0], strrpos($file_info[0], '.') + 1);
$file_info[] = $_FILES["uploaded_file"]["size"]/1024;
return $file_info;
}
function Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size) {
if($size_of_uploaded_file>$max_allowed_file_size ) { echo " El tamano del archivo debe ser menor que" . $max_allowed_file_size . " KB. <a href='cotizacion.html'>Elija un archivo mas pequeno</a>";
return false;
}
$allowed_extension = array("jpg", "jpeg", "gif", "bmp" , "dwg" , "doc", "text" , "xls" , "pdf");
for($i=0; $i<sizeof($allowed_extension); $i++) {
$allowed_extension[$i] = strtoupper($allowed_extension[$i]);
}
$type_of_uploaded_file = strtoupper($type_of_uploaded_file);
if(!(in_array(strtoupper($type_of_uploaded_file),$allowed_extension))) {
echo "Tu archivo tiene extensión:" . $type_of_uploaded_file . " . Este tipo de archivo no esta permitido. Favor elija un archivo de extension de imagen (jpg,gif,etc), pdf, autocad, excel, word o rar. <a href='cotizacion.html'>De click a qui para enviar un archivo con extension permitida.</a>";
return false;
}
return true;
}
function LoadUploadedFile($name_of_uploaded_file) {
move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "uploads/" . $name_of_uploaded_file);
return true;
}
function ComposeMail($name_of_uploaded_file) {
$name = $_POST['nombre'];
$user_message = $_POST['descripcion'];
$to = "cristina.arias.ing@gmail.com";
$subject="Una nueva solicitud fue realizada";
$from = $_POST['correo'];
$ubi = $_POST['ubicacion'];
$tel = $_POST['telefono'];
$emp = $_POST['empresa'];
$text = "Haz recibido de: " . $name ."\n"."Ubicado en:".$ubi."\n"."Telefono:".$tel. "\n"."Empresa:".$emp. "\n"."Envio lo siguiente: ".
$user_message;
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($name_of_uploaded_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
echo "Tu solicitud de cotización fue enviada exitosamente". "\n"."A la mayor brevedad te responderemos.<a href='index.html'>Regresar a inicio</a>";
}
}
?>