我正在嘗試製作一個小系統來幫助我工作。閱讀從這裏的一些文章,測試和失敗,我做了這個代碼工作:file_get_contents最後一個記錄
error_reporting(error_reporting() & ~E_NOTICE);
header("Content-Type: text/html; charset=ISO-8859-1", true);
$opts = array('http'=>array('method'=>"GET",
'header'=>"Accept-Language: pt-BR\r\n" .
"Cookie: ASPSESSIONIDSCSSRCRA=MHFGEDNDPHHBJDHGCMJKPDKN; ASPSESSIONIDQCSTTDRB=EKJNDDNDGGFMAHBFJABMJNAM".session_name()."=".session_id()."\r\n"));
$context = stream_context_create($opts);
session_write_close(); // unlock the file
$url = "http://www.comprasnet.gov.br/pregao/fornec/mensagens_acomp.asp?prgcod=622924";
$contents = file_get_contents($url, false, $context);
session_start(); // Lock the file
echo ($contents);
// Função para procura várias palavras em uma string
function procpalavras01 ($contents, $palavras, $resultado = 0) {
foreach ($palavras as $key => $value) {
$pos = stripos($contents, $value);
if ($pos !== false) {
$palavras_encontradas[] = $value; }
}
if (is_array($palavras_encontradas)) {
$palavras_encontradas = implode(",",$palavras_encontradas);
}
return $palavras_encontradas;
}
$palavras = array ("Ilma Chaves Pereira","19.026.964/0001-37","origina","correio","@");
$resultado = procpalavras01($contents, $palavras);
//Variáveis
$nome = ('ACLicita');
$mensagem = ('Pregoeiro chama no pregão');
$pregao = ('72016');
$uasg = ('160019');
$data_envio = date('d/m/Y');
$hora_envio = date('H:i:s');
// Compo E-mail
$arquivo = "
<style type='text/css'>
body {
margin:0px;
font-family:Verdane;
font-size:12px;
color: #666666;
}
a{
color: #666666;
text-decoration: none;
}
a:hover {
color: #FF0000;
text-decoration: none;
}
</style>
<html>
<table width='510' border='1' cellpadding='1' cellspacing='1' bgcolor='#CCCCCC'>
<tr>
<td>
<tr>
<td width='500'>Nome:$nome</td>
</tr>
<tr>
<td width='320'>Mensagem:$mensagem</td>
</tr>
<tr>
<td width='320'>Pregão:$pregao</td>
</tr>
<tr>
<td width='320'>Uasg:$uasg</td>
</tr>
<tr>
<td width='320'>Palavra Encontrada:$resultado</td>
</tr>
</td>
</tr>
<tr>
<td>Este e-mail foi enviado em <b>$data_envio</b> às <b>$hora_envio</b></td>
</tr>
</table>
</html>
";
//enviar
// emails para quem será enviado o formulário
$emailenviar = "[email protected]";
$destino = $emailenviar;
$assunto = "Atenção ao Pregão: " . $pregao . " Uasg: " . $uasg;
// É necessário indicar que o formato do e-mail é html
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ACLicita';
//$headers .= "Bcc: $EmailPadrao\r\n";
if ($resultado === null) {
} else {
$enviaremail = mail($destino, $assunto, $arquivo, $headers);
}
它工作正常,但我想這是鏈接(按日期和時間)上只檢查的最後一條消息,如果已經發送,不要再發送。該網站有一個刷新系統,所以每次網站刷新時我的代碼都會刷新,如果找到$ palavras中的單詞,就會發送另一封郵件。幫助我或以某種方式展示我,我怎麼能改正這一點。我不知道我是否清楚自己。
編輯1:代碼試圖inserto到表:
if ($resultado === null) {
} else {
$enviaremail = mail($destino, $assunto, $arquivo, $headers);
$sql = "INSERT INTO Licita (date, assunto, arquivo, email)
VALUES ('$date', '$assunto', '$arquivo', '$emailenviar')";
}
我們怎麼能知道它已經發送或不? –
那就是我想知道的一點。正如我之前所說,我不知道有關PHP的任何信息。我所知道的是,如果在鏈接中找到任何單詞,郵件就會到達。 –
你說:「我希望這隻檢查鏈接上的最後一條消息(按日期和小時),如果它已經發送了,不要再發送郵件」,我們如何判斷它是否已發送? td中是否有特定字詞表示它已發送? –