Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
**Saudações pessoal, venho aqui postar um probleminha e creio que será fácil de ser resolvido pelo pessoal mais experiente, então vamos lá, tenho um script de formulário com campos de anexos usando o input type o básico do html e usando o phpmailer como envio, este formulário funciona perfeitamente pelas alterações que fiz no mesmo, chega tanto as mensagens como os anexos em meu email belezinha, só que para as necessidades de um cliente precisaria usar um upload dinâmico como o UPLOADIFY creio que muitos já conhecem certo, eu até já implementei em meu código do form, ele até manda os anexos para a pasta do meu servidor, só que percebi que ele só manda para o servidor e não para o email e sei que preciso criar um função e alias se existir um método pra isso, de o botão uploadfy enviar ao mesmo tempo os anexos tanto para o servidor como para o email, entenderam pessoal, sei o o botão input do uploadify redireciona as imagens para a pasta no servidor enão fica em tmp_name temporário como no input do próprio form se puderem me ajudar serámuito bom segue abaixo o código..**
index.php
**<form method="post" id="contactform" action="pedido2.php" enctype="multipart/form-data" name="phmailer" onsubmit="return Checkit(this);">
<table width="593" align="center" class="table">
<tr>
<td colspan="2" class="table_header"></td>
</tr>
<tr>
<td class="attach_info" colspan="2">
</td>
</tr>
<tr>
<td class="attach_info" colspan="2">
<center><b>PREENCHA OS DADOS DE SEU IMÓVEL ABAIXO PARA DAR INICIO AO NOSSO TRABALHO:</b></center>
</td>
</tr>
<tr>
<td class="attach_info" colspan="2">
</td>
</tr>
<tr>
<td width="55%" class="table_body"> Seu Nome:</td>
<td width="45%" class="table_body"><input name="nome" type="text" size="20" value="<?php stripslashes(htmlspecialchars (utf8_decode($nome)));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Seu Email:</td>
<td width="45%" class="table_body"><input name="email" type="text" size="20" value="<?php stripslashes(htmlspecialchars($email));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Seu Telefone:</td>
<td width="45%" class="table_body"><input name="telefone" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($telefone));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Tipo de Imóvel:</td>
<td width="45%" class="table_body"><input name="imovel" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($imovel));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Número de Dormitórios:</td>
<td width="45%" class="table_body"><input name="dormitorios" type="text" size="20"value="<?php echo stripslashes(htmlspecialchars($dormitorios));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Número de Vagas:</td>
<td width="45%" class="table_body"><input name="vagas" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($vagas));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Preferência por Acabamento (s/n):</td>
<td width="45%" class="table_body"><input name="acabamento" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($acabamento));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Imóvel de CondomÃnio ou de Rua:</td>
<td width="45%" class="table_body"><input name="imovelcond" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($imovelcond));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Localidade:
</td>
<td width="45%" class="table_body"><input name="localidade" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($localidade));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Financiamento Bancário (s/n):</td>
<td width="45%" class="table_body"><input name="financiado" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($financiado));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Imóvel Residencial ou Comercial:</td>
<td width="45%" class="table_body"><input name="resid" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($resid));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Para Compra ou Locação:</td>
<td width="45%" class="table_body"><input name="compralocacao" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($compralocacao));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" height="24" class="table_body"> Valor:</td>
<td width="45%" class="table_body"><input name="valor" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($valor));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Como conheceu nosso Site:</td>
<td width="45%" class="table_body"><input name="site" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($site));?>" /><span class="error_message">*</span></td>
</tr>
<tr>
<td width="55%" class="table_body"> Assunto:</td>
<td width="45%" class="table_body">
<input name="assunto" type="text" size="20" value="<?php echo stripslashes(htmlspecialchars($assunto));?>" /><span class="error_message">*</span>
</td>
</tr>
<tr>
<td class="attach_info" colspan="2">
</td>
</tr>
<tr>
<td class="attach_info" colspan="2">
</td>
</tr>
<tr>
<td class="attach_info" colspan="2">
</td>
</tr>
<tr>
<td width="55%" class="table_body"> Adicione Fotos</td>
<td width="45%" class="table_body">
<br />
*//Início dos inputs do prórpio html e funciona normalmente os anexos//
<input type="file" name="arquivo_1" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_2" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_3" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_4" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_5" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_6" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_7" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_8" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_9" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_10" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_11" autofocus="autofocus" />
<br /><br />
<input type="file" name="arquivo_12" autofocus="autofocus" />
<br /><br />
//Fim dos inputs do prórpio html e funciona normalmente os anexos//**
**</td>
</tr>
<tr>
<td colspan="2" class="table_body">
<div align="center">Preencha mais informações sobre o Imóvel<span class="error_message">*</span><br />
</div>
<div align="center">
<table width="463" border="0">
<tr>
<td width="45"> </td>
<td width="361"><h8>
</h8></td>
<td width="43"> </td>
</tr>
</table>
<br />
</div>
</td>
</tr>
<tr>
<td colspan="2" class="table_footer">
<tr>
<td class="attach_info" colspan="2" >
<table width="542" border="0">
<tr>
<td width="137"> </td>
<td width="182">
//Início do input do uploadify que envia os anexos//**
<input id="arquivo_1" name="arquivo_1" type="file" multiple="true">
**//Fim do input do uploadify que envia os anexos//**
<input type="hidden" name="acao" value="enviar" />
<input type="submit" value="Enviar Formulário" class="btn"/>
</td>
<td width="17">
</td>
<td width="173">
<input type="reset" value="Limpar Dados" />
</td>
<td width="11"> </td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</form>
**//Início do java script do uploadify que manipula os anexos//**
**<a href="javascript:$('#arquivo_1').uploadify('cancel')">Cancela Arquivo</a> | <a href="javascript:$('#arquivo_1').uploadify('upload', '*')">Upload do Arquivos</a>
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#arquivo_1').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'pedido2.php',
'cancelImg' : 'cancel.png',
'width' : '100',
'height' : '25',
'folder' : 'temp',
'buttonText': 'Selecionar',
'fileDesc' : 'Image Files',
'fileExt' : '*.jpg;*.jpeg;*.gif;*.png',
'fileDesc' : 'Image Files',
'folder' : '/uploads',
'onComplete': function(event, queueID, fileObj, response, data){
sucesso(response);},
'removeCompleted': false,//Diretório, para onde vão ser movidas as imagens.
'auto' : true, // False para não começar automaticamente, e True para começar o upload automaticamente.
'multi' : true, // False para fazer upload apenas de um arquivo e True para vários arquivos.
'scriptData' : {'$arquivo_1':$('#arquivo_1').val() }
});
});
</script>
**//Fim do java script do uploadify que manipula os anexos//****
o enviar.php
**<?php
ini_set( 'default_charset', 'utf-8');
?>
<?php
/*
Uploadify
Copyright © 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
// Define a destination
$targetFolder = 'uploads'; // Relative to the root
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['uploads'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';echo 'Invalid file type.';
}
}
?>
<?php
$nome = strip_tags(trim($_POST['nome']));
$email = strip_tags(trim($_POST['email']));
$telefone = strip_tags(trim ($_POST['telefone']));
$imovel = strip_tags(trim($_POST['imovel']));
$dormitorios = strip_tags(trim ($_POST['dormitorios']));
$vagas = strip_tags(trim ($_POST['vagas']));
$acabamento = strip_tags(trim ($_POST['acabamento']));
$imovelcond = strip_tags(trim ($_POST['imovelcond']));
$localidade = strip_tags(trim($_POST['localidade']));
$financiado = strip_tags(trim($_POST['financiado']));
$resid = strip_tags(trim($_POST['resid']));
$compralocacao = strip_tags(trim($_POST['compralocacao']));
$valor = strip_tags(trim ($_POST['valor']));
$site = strip_tags(trim($_POST['site']));
$assunto = strip_tags(trim($_POST['assunto']));
$mensagem = strip_tags(trim ($_POST['mensagem']));
$arquivo_1 = $_FILES['arquivo_1'];
$arquivo_2 = $_FILES['arquivo_2'];
$arquivo_3 = $_FILES['arquivo_3'];
$arquivo_4 = $_FILES['arquivo_4'];
$arquivo_5 = $_FILES['arquivo_5'];
$arquivo_6 = $_FILES['arquivo_6'];
$arquivo_7 = $_FILES['arquivo_7'];
$arquivo_8 = $_FILES['arquivo_8'];
$arquivo_9 = $_FILES['arquivo_9'];
$arquivo_10 = $_FILES['arquivo_10'];
$arquivo_11 = $_FILES['arquivo_11'];
$arquivo_12 = $_FILES['arquivo_12'];$tamanho = 512000;
$tipos = array('image/jpeg', 'image/pjpeg');
if(empty($nome)){
echo "<script>alert('** Preenche o campo nome **');</script>";
echo "<script language='javascript'>history.back()</script>";echo "<script>alert('** Preenche o campo email **');</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(empty($mensagem)){
echo "<script>alert('** Preenche o campo mensagem **');</script>";
$msg = 'A Mensagem é Obrigatória';
echo "<script language='javascript'>history.back()</script>";
}elseif($arquivo['size'] > $tamanho){
$msg = 'O limite do tamanho do arquivo é de 500KB';
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_1["type"], $tipos) and !empty($arquivo_1['tmp_name'])){
echo "<script>alert('** O arquivo 1 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_2["type"], $tipos) and !empty($arquivo_2['tmp_name'])){
echo "<script>alert('** O arquivo 2 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(!in_array($arquivo_3["type"], $tipos) and !empty($arquivo_3['tmp_name'])){
echo "<script>alert('** O arquivo 3 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_4["type"], $tipos) and !empty($arquivo_4['tmp_name'])){
echo "<script>alert('** O arquivo 4 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_5["type"], $tipos) and !empty($arquivo_5['tmp_name'])){
echo "<script>alert('** O arquivo 5 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_6["type"], $tipos) and !empty($arquivo_6['tmp_name'])){
echo "<script>alert('** O arquivo 6 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_7["type"], $tipos) and !empty($arquivo_7['tmp_name'])){
echo "<script>alert('** O arquivo 7 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_8["type"], $tipos) and !empty($arquivo_8['tmp_name'])){
echo "<script>alert('** O arquivo 8 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_9["type"], $tipos) and !empty($arquivo_9['tmp_name'])){
echo "<script>alert('** O arquivo 9 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_10["type"], $tipos) and !empty($arquivo_10['tmp_name'])){
echo "<script>alert('** O arquivo 10 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_11["type"], $tipos) and !empty($arquivo_11['tmp_name'])){
echo "<script>alert('** O arquivo 11 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
elseif(!in_array($arquivo_12["type"], $tipos) and !empty($arquivo_12['tmp_name'])){
echo "<script>alert('** O arquivo 12 é inválido , são permitido apenas arquivos JPEG **');</script>";
echo "<script language='javascript'>history.back()</script>";
}
else{
require('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->Host = 'smtp.uol.com.br';
$mail->Username = 'email';
$mail->Password = 'senha';
$mail->SetFrom('email', "$nome");
$mail->AddAddress('email', "$nome");
$mail->Subject = 'Formulário de Contato';
$files = "uploads/";
$mail->AddAttachment($files);
//Aqui faz um loop pra pegar cada item do array
for($i =0; $i < $total; $i++){
//Verifica se foi enviado, e se o tipo é permitido
if(is_uploaded_file($files['tmp_name'][$i]) && in_array($files['type'][$i], $tipos)){
$body .= "Arquivo: ".$files['name'][$i]."<br >";
//Adiciona ao anexo
$mail->AddAttachment($files['tmp_name'][$i], $files['name'][$i]);
}
}
$body = "<html>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<table width='100%' border='1'>
<tr>
<th width='34%' scope='row'><strong>Nome :</strong> </th>
<th width='66%' scope='row'>{$nome}</th>
</tr>
<tr>
<th scope='row'><strong> E-mail :</strong></th>
<th scope='row'>{$email}</th>
</tr>
<tr>
<th scope='row'><strong> Telefone :</strong></th>
<th scope='row'>{$telefone}</th>
<tr>
<th scope='row'><strong> Imóvel :</strong></th>
<th scope='row'>{$imovel}</th>
</tr>
<tr>
<th scope='row'><strong> Dormitórios :</strong></th>
<th scope='row'>{$dormitorios}</th>
<tr>
<th scope='row'><strong> Vagas :</strong></th>
<th scope='row'>{$vagas}</th>
</tr>
<tr>
<th scope='row'><strong> Imóvel de CondomÃnio ou de Rua:</strong></th>
<th scope='row'>{$imovelcond}</th>
<tr>
<th scope='row'><strong> Localidade :</strong></th>
<th scope='row'>{$localidade}</th>
</tr>
<tr>
<th scope='row'><strong> Financiado :</strong></th>
<th scope='row'>{$financiado}</th>
<tr>
<th scope='row'><strong> Residencial ou Comercial :</strong></th>
<th scope='row'>{$resid}</th>
</tr>
<tr>
<th scope='row'><strong> Compra ou Locação :</strong></th>
<th scope='row'>{$compralocacao}</th>
<tr>
<th scope='row'><strong> Valor :</strong></th>
<th scope='row'>{$valor}</th>
</tr>
<tr>
<th scope='row'><strong> Site :</strong></th>
<th scope='row'>{$site}</th>
<tr>
<th scope='row'><strong> Assunto :</strong></th>
<th scope='row'>{$assunto}</th>
</tr>
<tr>
<th scope='row'><strong> Mensagem :</strong></th>
<th scope='row'>{$mensagem}</th>
<tr>
<th scope='row'> </th>
<th scope='row'> </th>
</tr>
</table>
<table width='100%' border='1'>
<tr>
<td><div align='center'><strong> Fotos </strong></div></td>
</tr>
</table>
<table width='100%' border='1'>
<tr>
<th width='11%' scope='row'> </th>
<th width='22%' scope='row'> </th>
<th width='67%' scope='row'> </th>
</tr>
<tr>
<th scope='row'> </th>
<th scope='row'> </th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo1 </strong> </th>
<th scope='row'>".$arquivo_1['name']."<br /><br /></th>
<th scope='row'>
</th>
</tr>
<tr>
<th scope='row'><strong>Arquivo2 </strong> </th>
<th scope='row'>".$arquivo_2['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo3 </strong> </th>
<th scope='row'>".$arquivo_3['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo4 </strong> </th>
<th scope='row'>".$arquivo_4['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo5 </strong> </th>
<th scope='row'>".$arquivo_5['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo6 </strong> </th>
<th scope='row'>".$arquivo_6['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo7 </strong> </th>
<th scope='row'>".$arquivo_7['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo8 </strong> </th>
<th scope='row'>".$arquivo_8['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo9 </strong> </th>
<th scope='row'>".$arquivo_9['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo10 </strong> </th>
<th scope='row'>".$arquivo_10['name']."<br /><br /></th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'><strong>Arquivo11 </strong> </th>
<th scope='row'>".$arquivo_11['name']."<br /><br /></th>
<th scope='row'> </th>
</tr><tr>
<th scope='row'><strong>Arquivo12 </strong> </th>
<th scope='row'>".$arquivo_12['name']."</th>
<th scope='row'> </th>
</tr>
<tr>
<th scope='row'> </th>
<th scope='row'> </th>
<th scope='row'> </th>
</tr>
</table></html>"
;
$mail->MsgHTML($body);
if(file_exists($arquivo_1["tmp_name"]) and !empty($arquivo_1)){
$mail->AddAttachment($_FILES['arquivo_1']['tmp_name'], $_FILES['arquivo_1']['name']);
}
if(file_exists($arquivo_2["tmp_name"]) and !empty($arquivo_2)){
$mail->AddAttachment($_FILES['arquivo_2']['tmp_name'], $_FILES['arquivo_2']['name']);
}
if(file_exists($arquivo_3["tmp_name"]) and !empty($arquivo_3)){
$mail->AddAttachment($_FILES['arquivo_3']['tmp_name'], $_FILES['arquivo_3']['name']);
}
if(file_exists($arquivo_4["tmp_name"]) and !empty($arquivo_4)){
$mail->AddAttachment($_FILES['arquivo_4']['tmp_name'], $_FILES['arquivo_4']['name']);
}
if(file_exists($arquivo_5["tmp_name"]) and !empty($arquivo_5)){
$mail->AddAttachment($_FILES['arquivo_5']['tmp_name'], $_FILES['arquivo_5']['name']);
}$mail->AddAttachment($_FILES['arquivo_6']['tmp_name'], $_FILES['arquivo_6']['name']);
}$mail->AddAttachment($_FILES['arquivo_7']['tmp_name'], $_FILES['arquivo_7']['name']);
}$mail->AddAttachment($_FILES['arquivo_8']['tmp_name'], $_FILES['arquivo_8']['name']);
}$mail->AddAttachment($_FILES['arquivo_9']['tmp_name'], $_FILES['arquivo_9']['name']);
}$mail->AddAttachment($_FILES['arquivo_10']['tmp_name'], $_FILES['arquivo_10']['name']);
}$mail->AddAttachment($_FILES['arquivo_11']['tmp_name'], $_FILES['arquivo_11']['name']);
}$mail->AddAttachment($_FILES['arquivo_12']['tmp_name'], $_FILES['arquivo_12']['name']);
}
if($mail->Send())
}
}
?>**
Deixei comentado para vcs visualizarem com mais facilidade desde já agradeço...
Carregando comentários...