How to place variables in email with phpmailer?

Asked

Viewed 793 times

-2

$sql = ("SELECT nome, datas FROM tabelas WHERE datediff(now(), data) <= 10 ");
$validade = mysql_query($sql);

while....
(codigo phpmailer)
// corpo da mensagem
$PHPMailer->Body = "<p>Faltam 10 dias ou menos para terminar a data do Documento  ".$Nome."</p>";

I need the message to show me the name and date that is less than 10 days to finish that is inserted in the comic.

I tried to test with just the name and it doesn’t work either.

$PHPMailer->Body = "<p>Faltam 10 dias ou menos para terminar a data do Documento ".$Nome."</p>";
  • Name is empty or html is not displayed?

  • Could you please clarify your question? It is unclear whether the problem is SQL or PHP.

  • If you can, put how you are treating the query return. It can often be a null or uninitialized variable. Use the error_reporting(E_ALL) is a good alternative to prevent mistakes go unnoticed.

  • Make sure the query is returning something; Make a separate test; You can put dynamic values at will. Just use how you are doing or insert {} into the variable ('{$name}').

  • The name is blank. I ask '.$Name.' and show me '..'

  • 1

    @user3253195 Can you place the complete query that is being performed? It is not clear whether the fields you are trying to use are actually collected in the query. On the other hand, how does the query get to the variable $Nome you’re working the data?

  • But when asking for names and dates in the query I can’t get the name? I already update

Show 2 more comments

2 answers

1

Your error is in the query. This is not how you calculate dates in Mysql/Mariadb. Note that you are adding an integer, but do not say what that integer is. The database in this case has a syntax that explains what type of interval it is, in this case the INTERVAL

SELECT * FROM tabela 
   WHERE data < (NOW() + INTERVAL 10 DAY) ## data menor que (agora + 10 dias)
         AND data > NOW() ## e maior que agora

Please see this table that talks about date calculation with INTERVAL http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

0

The Name and Date you want to show must be in your search.

select nome, data from ...

Your question does not seem to be about phpmailer but about how to query data. Please, detail better the structure of your table and which SGDB.

Browser other questions tagged

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