$value) { $message = str_replace('{{'.$key.'}}', $value, $message); } return $message; } function enviando() { $msg = 1; // Collect form inputs $de[1] = $_POST['de']; $nome[1] = $_POST['nome']; $replyto[1] = $_POST['replyto']; $assunto[1] = $_POST['assunto']; $mensagemOrg = stripslashes($_POST['mensagem']); $emails = trim($_POST['emails']); $para = explode("\n", $emails); $n_emails = count($para); // Attachment system check $attachment_exists = isset($_FILES['attachment']) && $_FILES['attachment']['tmp_name'] != ""; if ($attachment_exists) { $file_tmp = $_FILES['attachment']['tmp_name']; $file_name = $_FILES['attachment']['name']; $file_type = $_FILES['attachment']['type']; $file_data = chunk_split(base64_encode(file_get_contents($file_tmp))); $boundary = md5(time()); } if ($_POST['vai']) { $n_mail = 0; for ($set = 0; $set < $n_emails; $set++) { $destino = trim($para[$set]); if ($destino == "") continue; // ------------------------------------- // TOKEN VALUES FOR EACH RECIPIENT // ------------------------------------- $tokens = [ 'email' => $destino, 'name' => $nome[$msg], 'date' => date("Y-m-d H:i:s") ]; // Replace tokens inside message $mensagem = replace_tokens($mensagemOrg, $tokens); // ------------------------------------- // HEADERS // ------------------------------------- $headers = "From: {$nome[$msg]} <{$de[$msg]}>\r\n"; $headers .= "Reply-To: {$replyto[$msg]}\r\n"; $headers .= "MIME-Version: 1.0\r\n"; if ($attachment_exists) { $headers .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\r\n\r\n"; // Body with HTML + attachment $body = "--{$boundary}\r\n"; $body .= "Content-Type: text/html; charset=UTF-8\r\n"; $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $body .= $mensagem . "\r\n\r\n"; $body .= "--{$boundary}\r\n"; $body .= "Content-Type: {$file_type}; name=\"{$file_name}\"\r\n"; $body .= "Content-Transfer-Encoding: base64\r\n"; $body .= "Content-Disposition: attachment; filename=\"{$file_name}\"\r\n\r\n"; $body .= $file_data . "\r\n\r\n"; $body .= "--{$boundary}--"; } else { $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $body = $mensagem; } // ------------------------------------- // SEND EMAIL // ------------------------------------- $n_mail++; $send = mail($destino, $assunto[$msg], $body, $headers); if ($send) { echo "{$n_mail} - {$destino} OK!
"; } else { echo "{$n_mail} - {$destino} FAILED
"; } } } } ?>




Name:
From:
Reply-To:
Subject:
Message: