Good afternoon!
I'm having a little problem related to sending an email attachment.
I have three scripts in php, with a envia_email.php
<?php
//autenticacao
//-----------------
//$porta = ''; // porta padrao: 25
//$secure = ''; // 'ssl' ou 'tls'
//-----------------
$host = 'meudominio.com.br';
$userName = 'email@meudominio.com.br';
$senha = 'xxxxxxx';
//----------------
$from = 'email@meudominio.com.br';
$fromName = 'cadastro';
$addAddress = 'cadastros@meudominio.com.br';//destinatario
$nameAddAddress = 'Site';//nome destinatario
$charset = 'iso-8859-1';
// $subject = ''; //titulo
$arquivo = '';
$tipoTexto = 'html';
$body = 'Dados';//corpo do email
require("phpmailer/class.phpmailer.php");
// Starts class PHPMailer
$mail = new PHPMailer();
// Defines the data server and connection type
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$mail->IsSMTP(); // Define que a mensagem será SMTP
$mail->Host = $host; // Endereço do servidor SMTP
$mail->SMTPAuth = true; // Usa autenticação SMTP? (opcional)
$mail->Username = $userName; // Usuário do servidor SMTP
$mail->Password = $senha; // Senha do servidor SMTP
$mail->SMTPSecure = $secure;
$mail->Port = $porta;
// Sets the sender
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$mail->From = $from; // Seu e-mail
$mail->FromName = $fromName; // Seu nome
// Sets the recipient (s)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$mail->AddAddress($addAddress, $nameAddAddress);
//$mail->AddAddress('emaildaicional@gmail.com');
//$mail->AddCC('ciclano@site.net', 'Ciclano'); // copies
//$mail->AddBCC('fulano@dominio.com.br', 'Fulano da Silva'); // copies Oculta
// defines the technical data of the Post
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if ($tipoTexto=='html'){
$mail->IsHTML(true); // Sets the e-mail will be sent as HTML
}elseif($tipoTexto=='texto'){
$mail->IsHTML(false); // Sets the e-mail will be sent as HTML
}
$mail->CharSet = $charset; // Charset da mensagem (opcional)
// Sets the message (Subject and Text)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$mail->Subject = $subject; // Subject of the message
$mail->Body = $body;
$mail->AltBody = '\n \n \n Teste de envio phpmailer \r\n ';
// Sets attachments (opcional)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if ($arquivo!=""){
$mail->AddAttachment($arquivo, 'autodetect', 'attachment', 'quoted-printable'); // Inserts an attachment
}
// Envia o e-mail
$enviado = $mail->Send();
// Clears the recipients and attachments
$mail->ClearAllRecipients();
$mail->ClearAttachments();
// Displays a result message
if ($enviado) {
echo "E-mail sent in succession!";
} else {
echo "Unable to send e-mail.<br /><br />";
echo "<b>Error information:</b> <br />" . $mail->ErrorInfo;
}
?>
this problem without sending the email.
exp.php file
<?php
include "conexao.php";
session_start();
include "envia_email.php";
$vInicio = 0;
if ($_REQUEST['de'] != '')
{
$vInicio = $_REQUEST['de'];
}
$vFim = 0;
if ($_REQUEST['ate'] != '')
{
$vFim = $_REQUEST['ate'];
}
$vlimite = " ";
$voffset = "";
if ($_REQUEST['offset'] != "")
{
$vOffset = " OFFSET "& $_REQUEST['offset'];
$vlimite = " LIMIT 50 ";
}
$vCond = "";
if ($_REQUEST['pendente'] == "1")
{
$vCond = " enviar = 0 ";
$vlimite = " LIMIT 50 ";
}
$campos = "*";
....
/*************** Building file SCV ***************/
$handle = fopen ("send/cv" . $cpf . ".scv", "w+");
....
/* End of file */
fwrite($handle, $conteudo);
fclose($handle);
$linhaatual++;
// $reg = mysql_fetch_row($resultado);
//prepares and sends the data (file) via email
$p_codigo = $cpf;
$assunto = 'Cadastro de clientes';
$mensagem = 'Envio do cadastrado pelo site';
$arquivo = "send/cv".$cpf.".scv";
sendMail("cadastro@meudominio.com.br", $mensagem, $assunto,$arquivo );
} // fim while
}
else
{
echo "Error! Could not load data.";
}
?>
This file takes the data and turns it into the database file .scv
But I can not attach this file.
I was using Sendmail, and it worked, but not with my server but with a different server and I could not configure the account to receive cadastro@meudominio.com.br
Someone could help me?
thank you
Ricardo |