Return and reply to sending the email in the layout

0

I have a mailing system that receives the name and email of the database and sends it.

But when I call the function it will load all the emails on the screen with its result in front.

[email protected] => enviado 
[email protected] => erro 
[email protected] => enviado 

Sofarsogood:)

Moremydoubtandthenext,Ineedtointegratethelayoutthatishere.

Here in Enviando msg pra caixa do ==> Aguardando ação no "Awaiting action" I want to show which email is being sent to each shipment in the following way:

Enviando msg pra caixa do ==> [email protected]
    
asked by anonymous 30.03.2015 / 22:16

1 answer

2

I think I understood what you want, now. Simply show a STATUS of the EMAIL SEND action. There are several ways to do this, I'll tell you how I would do it.

Imagine a SALES LETTER :

  

Hello, {NAME} This is a sales letter, blaw, blaw, blaw, blaw, ...   blaw, blaw, blaw, blaw.

And you have to send to an email list. Now imagine that you have a table with this mailing list.

TBL_EMAIL

ID | NOME     | EMAIL             | STATUS
1  | Fulano   | [email protected]   | 0
2  | Beutrano | [email protected] | 0
3  | Cicrano  | [email protected]  | 0

Explanation of STATUS

  • 0 = WAITING FOR DELIVERY
  • 1 = SENT

Now you need to start the action and pick up an email to start sending the email. With a SELECT will need return only one email address to be sent.

SELECT * FROM 'TBL_EMAIL' WHERE 'STATUS'=0 LIMIT 1

This will only bring you one email at a time.

FRONTEND

Now let's go to the frontend. At this point you will need a page for the action to be displayed and executed. For example www.site.com.br/enviando.php and in this page you will have a looped script to follow the actions.

www.site.com.br/enviando.php

<p id="status"></p>

<script>
    function realtime() {
        $.get("ajax-email.php", {}, function(data) {
            $("#status").html(data.email +' - ' data.status + '<br>');
        }).done(function () {
            // se não dizer que espere, apenas coloque 0 ou deixe apenas a função realtime()
            setTimeout(function() {
                realtime();
            }, 100);
        });
    }

    // função sendo chamada pela primera vez
    realtime();
</script>

ON THE PAGE ajax-email.php

When the email sending action is triggered.

// Primeiro vc faz um select no email com o SQL que mencionei acima
// SELECT * FROM 'TBL_EMAIL' WHERE 'STATUS'=0 LIMIT 1

// Vo meio vc terá suas funções me metodos para enviar um email
$return = acao_enviar($nome, $email, $mensagem);

// verificando se deu certo o envio de email
if($return) {
    $status = 'Sucesso';

    // neste ponto vc muda o statos no banco de dados 
    // UPDATE TBL_EMAIL SET STATUS=1 WHERE ID=$id

} else {
    $erro = 1;
    $status = 'Erro';
}


// Por fim o retorno final da ação
die(json_encode(array(
    'erro'  => $errro,
    'email'  => $email,
    'status' => $status
)));

The page should look like this:

[email protected] - Sucesso
[email protected] - Erro
[email protected] - Sucesso

This is pretty basic, but it's just for you to get an idea of how to do and what I understand

    
30.03.2015 / 23:12