Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $nome = strip_tags(trim($_POST['nome']));
- $email = strip_tags(trim($_POST['email']));
- $telefone = strip_tags(trim($_POST['telefone']));
- $assunto = strip_tags(trim($_POST['assunto']));
- $mensagem = strip_tags(trim($_POST['mensagem']));
- $arquivo = $_POST['arquivo'];
- $tamanho = 5242880; //5 megabytes
- $tipos = array(
- 'image/jpeg',
- 'image/pjpeg'
- ); //tipos de arquivos
- $erro = array();
- if (empty($nome)) {
- $erro[] = "Digite seu nome";
- }
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $erro[] = "Digite um e-mail válido";
- }
- if (empty($telefone)) {
- $erro[] = "Digite seu telefone";
- }
- if (empty($assunto) || $assunto == 'Assunto') {
- $erro[] = "Selecione um assunto";
- }
- if (empty($mensagem)) {
- $erro[] = "Digite uma mensagem";
- }
- if (!is_uploaded_file($arquivo['tmp_name'])) {
- $erro[] = 'O arquivo é obrigátorio';
- } if ($arquivo['size'] > $tamanho) {
- $erro[] = 'O limite do arquivo é de 5 megabytes';
- } if (!in_array($arquivo['type'], $tipos)) {
- $erro[] = 'O tipo do arquivo permitido é apenas JPEG';
- } else if (count($erro) < 1) :
- require_once 'phpmailer/PHPMailerAutoload.php';
- $Email = new PHPMailer();
- $Email->setLanguage('br');
- //Define dados do servidor e tipo de conexão
- $host = 'smtp.gmail.com';
- $username = '';
- $senha = '';
- $porta = 587;
- $secure = 'tsl';
- //Email e nome de quem vai receber o email
- $receber_email = 'sergiojfjfjf@gmail.com';
- $receber_nome = 'Sérgio Machado';
- $from = $username;
- $fromName = 'Sérgio Machado';
- $Email->isSMTP();
- $Email->Host = $host;
- $Email->SMTPAuth = true;
- $Email->Username = $username;
- $Email->Password = $senha;
- $Email->Port = $porta;
- $Email->SMTPSecure = $secure;
- $Email->From = $from;
- $Email->FromName = $fromName;
- $Email->addReplyTo($email, $nome);
- $Email->addAddress($receber_email, $receber_nome);
- $Email->isHTML(true);
- $Email->CharSet = 'utf-8';
- $Email->WordWrap = 70;
- $Email->Subject = $assunto;
- $body = "<strong>Nome: </strong>{$nome} <br />
- <strong>E-Mail: </strong>{$email} <br />
- <strong>Telefone: </strong>{$telefone} <br />
- <strong>Assunto: </strong>{$assunto} <br />
- <strong>Mensagem: </strong>{$mensagem} <br />
- <strong>Arquivo em anexo: </strong>{$arquivo['name']} <br />";
- $Email->msgHTML($body);
- $Email->AddAttachment($arquivo['tmp_name'], $arquivo['name']);
- //Verifica se a mensagem foi enviada ou não.
- if ($Email->Send()) {
- echo '<p class="resposta email-enviado">E-mail enviado com sucesso</p>';
- } else {
- echo '<p class="resposta email-nao-enviado">Error: e-mail não enviado, por favor tente outra vez!</p>';
- }
- endif;
- if (count($erro) >= 1) {
- echo '<ul class="resposta email-nao-validado">';
- foreach ($erro as $err) {
- echo '<li>' . $err . '</li>';
- }
- echo '</ul>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement