5
How to send emails automatically using PHP?
I have a form that receives several dates and when it was 10 days before the deadline, send a message to several people with the warning.
I’ve been told to use the Cron job. But this serves only to make the routine run.
What I need is help with the code because I’ve been trying to put the code in the Windows task manager and nothing.
<?php
include(conectar.php);
$conn = @mysql_connect($local_serve, $usuario_serve, $senha_serve, $banco_de_dados)
or die ("O servidor não responde!");
// conecta-se ao banco de dados
$db = @mysql_select_db($banco_de_dados,$conn)
or die ("Não foi possivel ligar-se a Base de Dados!");
$validade = ("SELECT Nome, AlvaraValidade, AcidenteValidade, SeguroValidade, FinancasValidade, SocialValidade, RemuneracaoValidade, InstaladorValidade, MontadorValidade, MedicaValidade, ProjectistaValidade, GasValidade, RedesValidade, SoldadorValidade, MecanicoValidade, ClasSoldadorValidade, MaquinaValidade1, MaquinaValidade2, MaquinaValidade3, MaquinaTopoValidade FROM tb_eqipamentos, tb_detalhe_trabalhador, tb_trabalhador");
$now = new DateTime();
$diff = $now ($validade);
if ($diff <= 10){
$mail_to = "[email protected]";
while ($row = mysql_fetch_array($query)){
echo $row['name']." - ".$row['email']."\n";
$mail_to = $row['email'].", ";
}
if (!empty($mail_to)){
sendEmail($mail_to);
}
?>
What would be watering?
– Maniero
Improve your code, it’s all "piled up" and so make it difficult for those who want to help you.
– NovoK
@user3253195, avoid using
<?
(instead use<?php
,@
(can use for exampleisset()
) and the functionsmysql_
have already been depreciated. not to have future problems.– rray
@user3253195, Will php run on a linux or windows server? For Windows servers you have to add the data of an smtp server to the PHP settings, in the case if a linux server PHP uses sendmail to send. Your problem may be happening at this point.
– Thiago Silva
It will be for use on a Windows server. Ah Maybe I’m missing that part anyway
– ChrisAdler