Advertisement
Guest User

Untitled

a guest
Jun 21st, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. $nome = strip_tags(trim($_POST['nome']));
  2. $email = strip_tags(trim($_POST['email']));
  3. $telefone = strip_tags(trim($_POST['telefone']));
  4. $assunto = strip_tags(trim($_POST['assunto']));
  5. $mensagem = strip_tags(trim($_POST['mensagem']));
  6. $arquivo = $_POST['arquivo'];
  7.  
  8. $tamanho = 5242880; //5 megabytes
  9. $tipos = array(
  10. 'image/jpeg',
  11. 'image/pjpeg'
  12. ); //tipos de arquivos
  13.  
  14.  
  15. $erro = array();
  16. if (empty($nome)) {
  17. $erro[] = "Digite seu nome";
  18. }
  19.  
  20. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  21. $erro[] = "Digite um e-mail válido";
  22. }
  23. if (empty($telefone)) {
  24. $erro[] = "Digite seu telefone";
  25. }
  26. if (empty($assunto) || $assunto == 'Assunto') {
  27. $erro[] = "Selecione um assunto";
  28. }
  29. if (empty($mensagem)) {
  30. $erro[] = "Digite uma mensagem";
  31. }
  32.  
  33. if (!is_uploaded_file($arquivo['tmp_name'])) {
  34. $erro[] = 'O arquivo é obrigátorio';
  35. } if ($arquivo['size'] > $tamanho) {
  36. $erro[] = 'O limite do arquivo é de 5 megabytes';
  37. } if (!in_array($arquivo['type'], $tipos)) {
  38. $erro[] = 'O tipo do arquivo permitido é apenas JPEG';
  39. } else if (count($erro) < 1) :
  40.  
  41. require_once 'phpmailer/PHPMailerAutoload.php';
  42.  
  43. $Email = new PHPMailer();
  44. $Email->setLanguage('br');
  45.  
  46. //Define dados do servidor e tipo de conexão
  47. $host = 'smtp.gmail.com';
  48. $username = '';
  49. $senha = '';
  50. $porta = 587;
  51. $secure = 'tsl';
  52.  
  53. //Email e nome de quem vai receber o email
  54. $receber_email = 'sergiojfjfjf@gmail.com';
  55. $receber_nome = 'Sérgio Machado';
  56.  
  57. $from = $username;
  58. $fromName = 'Sérgio Machado';
  59.  
  60. $Email->isSMTP();
  61. $Email->Host = $host;
  62. $Email->SMTPAuth = true;
  63. $Email->Username = $username;
  64. $Email->Password = $senha;
  65. $Email->Port = $porta;
  66. $Email->SMTPSecure = $secure;
  67.  
  68. $Email->From = $from;
  69. $Email->FromName = $fromName;
  70. $Email->addReplyTo($email, $nome);
  71. $Email->addAddress($receber_email, $receber_nome);
  72.  
  73. $Email->isHTML(true);
  74. $Email->CharSet = 'utf-8';
  75. $Email->WordWrap = 70;
  76.  
  77. $Email->Subject = $assunto;
  78.  
  79. $body = "<strong>Nome: </strong>{$nome} <br />
  80. <strong>E-Mail: </strong>{$email} <br />
  81. <strong>Telefone: </strong>{$telefone} <br />
  82. <strong>Assunto: </strong>{$assunto} <br />
  83. <strong>Mensagem: </strong>{$mensagem} <br />
  84. <strong>Arquivo em anexo: </strong>{$arquivo['name']} <br />";
  85.  
  86. $Email->msgHTML($body);
  87. $Email->AddAttachment($arquivo['tmp_name'], $arquivo['name']);
  88.  
  89. //Verifica se a mensagem foi enviada ou não.
  90. if ($Email->Send()) {
  91. echo '<p class="resposta email-enviado">E-mail enviado com sucesso</p>';
  92. } else {
  93. echo '<p class="resposta email-nao-enviado">Error: e-mail não enviado, por favor tente outra vez!</p>';
  94. }
  95. endif;
  96.  
  97. if (count($erro) >= 1) {
  98. echo '<ul class="resposta email-nao-validado">';
  99. foreach ($erro as $err) {
  100. echo '<li>' . $err . '</li>';
  101. }
  102. echo '</ul>';
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement