How to create an email resend after 30 days?

Asked

Viewed 51 times

-1

I am creating an email resend, I need it to work as follows, I want you to check the table and check all emails, if it is less than 30 days forward the email. I have this code below where before it was working, but the first email longer than 30 days that is found sends the email to him and the others does not send kkk. Could someone help me? I thank you in advance.

<?php
#dados para conexão com banco de dados 
$strcon = mysqli_connect('localhost','root','','integracao') or die('Erro ao conectar ao banco de dados');
$search = mysqli_query($strcon,"SELECT * FROM tb_emprestimo WHERE DATA >= '(date_sub(curdate(), interval 30 day))'");
$linha =mysqli_fetch_array($search);
$emailDestino = $linha["EMAIL"];
$destinatario = $linha["NOME_PESSOA"];
if(@mysqli_num_rows($search) > 0){
 
// Caminho da biblioteca PHPMailer
require 'phpMailer/class.phpmailer.php';

// Instância do objeto PHPMailer
$mail = new PHPMailer;

// Configura para envio de e-mails usando SMTP
$mail->isSMTP();

// Servidor SMTP
$mail->Host = 'smtp.gmail.com';

// Usar autenticação SMTP
$mail->SMTPAuth = true;

// Usuário da conta
$mail->Username = '********@gmail.com';

// Senha da conta
$mail->Password = '********';

// Tipo de encriptação que será usado na conexão SMTP
$mail->SMTPSecure = 'ssl';

// Porta do servidor SMTP
$mail->Port = 465;

// Informa se vamos enviar mensagens usando HTML
$mail->IsHTML(true);

// Email do Remetente
$mail->From = '*********@gmail.com';
// Nome do Remetente
$mail->FromName = 'ZINA PORTO';

// Endereço do e-mail do destinatário
$mail->addAddress($emailDestino);

// Assunto do e-mail
$mail->Subject = 'Assunto';

// Mensagem que vai no corpo do e-mail
$mail->Body = '<h2>Olá, '.$destinatario.'</h2>
<p> MENSAGEM PARA DESTINATARIO</p>';
   
}

?>

  • In the title you say "after 30 days" and in the text "if it is less than 30 days send the email"... and in the code you use the operator >=.... In the code will pick up the records with 30 days or more. Got confused to know the objective due to the contradictions of information.

  • I meant if the date in the bank is shorter than today’s date. Ex: You are in the bank 01/03/2019, this is smaller than today 28/04/2019, consequently has more than 30 days. So you have to send the email. Am I right? Got it?

1 answer

2


To return only the records where the column DATA (assuming the column is of the date or datetime) has a date equal to or earlier than 30 days from the current date, you should use the operator <= (smaller or equal) and not >= (greater or equal) and with the function date_sub() out of single quotes:

SELECT * FROM tb_emprestimo WHERE DATA <= date_sub(curdate(), interval 30 day)

This means you will only get the PREVIOUS dates (smaller) to 29 days behind (less than or equal to 30), not counting the current date.

If today are 29/04, will catch any date before 31/03, because from 30/03 until 29/04 are exact 30 days.

  • Bro didn’t work. Nothing’s going on. You think that email trigger code is right that way. you got some dirt on how I can do?

  • But you’re finding the records?

  • Bro I went to take a right look at my Bank, the date column and TIMESTEMP. I will correct here and return.

Browser other questions tagged

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