I have a script for an email sending in php and i have to put it in the public folder. The script is working perfectly but i would like to send variables to my script. The variables are declared in a controller inside the application folder, they are the result of a database. The script has to be executed every morning. How can i pass the variables ?
I want to put the script outside the application because i want to execute the script with cron. If i put the script in the application folder, he wont be executed because the connection in the application require a loginAction.
the script is called emailsuivi.php. The variables to send are called $suiviprodmois and $suiviprodjours. Im using ZendFramework 1.
the app folder :
The script :
$dateCrea = date('Ym', mktime(0,0,0,date("m"),0,date("Y")));
$curDate = date("Y-m-d H:i:s");
ini_set('SMTP','mail.viapost-services.fr');
$mails = 'Nicolas.BOULEIN@viapost.fr';
$sujet = 'Suivi de production';
$message = "
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
</head>
<body>
<style>
body{
font-family : Arial;
}
h1, h2{
text-align : center;
}
table {
font-family : Arial;
border : 1px solid black;
width : 100%;
}
table th {
border : 1px solid white;
height: 25px;
text-align: center;
padding: 0px;
background: #3A81A7;
color: white;
background-color:#3a81a7;
}
table td {
border : 1px solid black;
padding: 0 1px 5px 0;
text-align : center;
}
</style>
<h1> Suivi de production </h1>
<h2> Le : ".$curDate."</h2>
<h3> Suivi des dépôts du J-1 </h3>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th colspan='3'>Résultat admission</th>
<th colspan='3'>Résultat PEC</th>
<th colspan='3'>Facturation HORS BORD</th>
</tr>
<tr>
<th>TYPE</th>
<th>IMPORT</th>
<th>RADM_OK</th>
<th>RADM_REJET</th>
<th>RADM_KO</th>
<th>RPEC_OK</th>
<th>RPEC_REJET</th>
<th>RPEC_KO</th>
<th>FACTU_OK</th>
<th>FACTU_REJET</th>
<th>FACTU_KO</th>
</tr>
</thead>
<tbody>";
foreach ($suiviprodjours as $arr){
$message .="<tr>";
foreach ($arr as $key => $val){
$message .="<td>".$arr[$key]."</td>";
}
$message .="</tr>";
}
$message .="</tbody>
</table>
</ br>
</ br>
</ br>
</ br>
<h3> Suivi des dépôts du M-1 </h3>
<table>
<thead>
<tr>
<th>OBJET</th>
<th>ATTENTE</th>
<th>ENCOURS</th>
<th>FINADM</th>
<th>FACTURE</th>
<th>ACQUITTE</th>
</tr>
</thead>
<tbody>";
foreach ($suiviprodmois as $arr){
$message .="<tr>";
foreach ($arr as $key => $val){
$message .="<td>".$arr[$key]."</td>";
}
$message .="</tr>";
}
$message .="</tbody>
</table>
</body>";
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'From: SAGAPEC <sagapec@viapost.fr>' . "
";
$headers .= 'Content-type: text/html; charset=UTF-8' . "
";
mail($mails,$sujet,$message,$headers)
The function for the variables :
public function suiviprodAction(){
// Connexion au fichier de label
$this->view->lib = $this->_labelsFile;
$oDepotAdmin = new Services_DepotAdmin();
$suiviprodjours = $oDepotAdmin->suiviProdJours();
$dateCrea = date('Ym', mktime(0,0,0,date("m"),0,date("Y")));
$curDate = date("Y-m-d H:i:s");
$suiviprodmois = $oDepotAdmin->suiviProdMois($dateCrea);
//$_SESSION['suiviprodmois'] = $suiviprodmois;
}
the localisation of this function :