Sending the contents of a div by email with php Mailer

Asked

Viewed 352 times

0

I have the following code:

<?php require_once ("cabecalho.php");?>
<div id="menor">
    <div class="input-field col s12">
        <form action="envia-texto.php" method="post">
            <div id="texto" name="texto">
                <h5 class="center-align black-text"><?php ini_set('display_errors', 1);
                    ini_set('display_startup_errors', 1);
                    error_reporting(E_ALL);
                    if(isset($_POST['titulo'])){

                        echo $_POST['titulo'] . ' ';
                    }?>                     
                </h5><br>
                <h6 class="black-text">
                    <?php ini_set('display_errors', 1);
                    ini_set('display_startup_errors', 1);
                    error_reporting(E_ALL);

                    if(isset($_POST['introducao'])) {

                        echo $_POST['introducao'] . ' ';
                    }?>
                </h6>
                <h6 class="black-text">
                    <?php ini_set('display_errors', 1);
                    ini_set('display_startup_errors', 1);
                    error_reporting(E_ALL);

                    if(isset($_POST['argumento1'])) {

                        echo $_POST['argumento1'] . ' ';
                    }?>
                </h6>
                <h6 class="black-text">
                    <?php ini_set('display_errors', 1);
                    ini_set('display_startup_errors', 1);
                    error_reporting(E_ALL);

                    if(isset($_POST['argumento2'])) {

                        echo $_POST['argumento2'] . ' ';
                    }?>
                </h6>
                <h6 class="black-text">
                    <?php ini_set('display_errors', 1);
                    ini_set('display_startup_errors', 1);
                    error_reporting(E_ALL);

                    if(isset($_POST['argumento3'])) {

                        echo $_POST['argumento3'] . ' ';
                    }?>
                </h6>
                <h6 class="black-text">
                    <?php ini_set('display_errors', 1);
                    ini_set('display_startup_errors', 1);
                    error_reporting(E_ALL);

                    if(isset($_POST['conclusao'])) {

                        echo $_POST['conclusao'] . ' ';
                    }?>
                </h6>
            </div>
            <div class="input-field">
                <input class="validate" id="nome" type="text" name="nome">
                <label for="nome" class="black-text">Nome Completo</label>
            </div>
            <div class="input-field">
                <input class="validate" id="email1" type="email" name="email1">
                <label for="email1" class="black-text">Seu Email</label>
            </div>
            <div class="input-field">
                <input type="password" name="senha" id="senha">
                <label for="senha" class="black-text">Sua Senha</label>
            </div>
            <div class="input-field">
                <input class="validate" id="email2" type="email" name="email2">
                <label for="email2" class="black-text">Email Alvo</label>
            </div>

        </div>
        <div class="row">
            <div class="col s12 center">
                <br>
                <button class="btn waves-effect waves-light red" value="Enviar2" type="submit">
                    <i class="material-icons right">send</i>enviar
                </button>
            </div>
        </div>
    </form>
</div>

<?php include 'rodape.php';?>

When you click the send button, the code is loaded enviar-texto.php, which is this

<?php
session_start();
$texto = $_POST["texto"];
$email2 = $_POST["email2"];
$email1 = $_POST["email1"];
$senha = $_POST["senha"];
$nome = $_POST["nome"];

require_once("PHPMailerAutoload.php");

$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = 'utf-8';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $email1;
$mail->Password = $senha;

$mail->setFrom($email1, $nome);
$mail->addAddress($email2);
$mail->Subject = "Redação de um usuário VestCollege";
$mail->msgHTML("<html>{$texto}</html>");
$mail->AltBody = $texto;
if($mail->send()) {
  header("Location: home.php");
} else {
  $_SESSION["danger"] = "Erro ao enviar mensagem " . $mail->ErrorInfo;
  header("Location: phptexto.php");
}
die();

It works like this: it fills the fields title, introduction, argument 1, etc. Then these pieces are joined and loaded inside the div "text", but when I send by email the div goes empty there and I don’t know what the problem is.

If it’s relevant to say I’m using materialize css framework. please help me because I don’t know what to do.

  • In your context you cannot send data contained in a div

  • and have any idea how I can make it work?

  • plays the contents of the div inside <textarea id="textA" name="textA" style="display:None"> CONTENT HERE</textarea> and send $text there = $_POST["textA"];

  • first these display: None ta making the textarea not appear on the screen. according I took these display there instead of appearing the typed text ta appearing the html tags you have inside the div

  • Young man, the display:None in the textarea is not to appear even on the screen since this information is already in the div. It’s just so you can upload this content into this div to send-text.php.

  • It worked out thanks

  • I published as a reply, read https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

  • thanks did not know this answer business. I marked there now

Show 3 more comments

1 answer

0


Play div content within a textarea display:none (not to appear even on the screen)

<textarea id="textoA" name="textoA" style="display:none"> CONTEUDO AQUI</textarea>

and on the send-text page.php recovers so

$texto = $_POST["textoA"];

Contents of the div

<textarea id="textoA" name="textoA" style="display:none">            
    <h5 class="center-align black-text">
    <?php
        echo $_POST['titulo'] . ' ';
    ?>                     
    </h5><br>
    ....................
    ....................
    ....................
</textarea>   

Browser other questions tagged

You are not signed in. Login or sign up in order to post.