Script PHP who calls another script PHP - php

I beg your pardon if some part of the code is written in italian, but I'm trying to make a script for my work, and I want to split two scripts, where in the main script there is a call to another script with the require function.
The main script is the following:
\<?php
require('c:/include_connessione/ldbproxy.inc.php');
//define('DB2SERVER' , 'udbsrv0e:50004');
define('DB2SERVER' , '192.168.8.128:50004');
define('DB' , 'WAREHSOA');
define('DBUSR' , 'db2itsoa');
define('DBPWD' , 'db2itsoa');
$styleSpieg="style='font-family:arial;font-size: 10pt;text-align: left;'";
function TRACE($str)
{
$fp=fopen('c:/Manutenzione/confronti_itcam/confronti_itcam.log', 'a');
if($fp)
{
fprintf($fp, date('Y-m-d H:i:s') . ' ' . $str . "\n");
fclose($fp);
}
}
TRACE("START");
$conn = new ldbproxy();
if(! $conn->connect_db2(DB2SERVER, DB, DBUSR, DBPWD))
{
TRACE('cannot connect to ' . DB2SERVER . ': ' . $conn->errorMsg);
die();
}
$confronti_DataPower=require("confronti_itcam_DataPower.php");
$conn->close();
$subject = "Confronto eventi SOA del ".date('d-m-Y',strtotime("-1 days"));
$spiegazione = "<td $styleSpieg align=left >
<b>I dati che seguono hanno lo scopo di confrontare gli eventi dell'applicativo ITCAmfSOA che vengono scritti dall'agent di monitoraggio sulle tabelle del DB2 WAREHSOA, in particolare:<br>
- confronto tra eventi di request sulla tabella Services_Inventory_610 (di seguito SI) e la tabella Services_Inventory_ReqID_610 (di seguito SI_ReqID)<br>
- confronto tra eventi di fault sulla tabella Services_Inventory_610 (SI) e la tabella Fault_Log_Table_610 (di seguito FLT) </b>
</td>";
$header = 'From:tivoli#inps.it' . "\r\n";
$header .= "X-Mailer: \n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$out = "<html>
<body>
<table>
<tr>
$spiegazione
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td>
$confronti_DataPower
</td>
</tr>
<tr>
</tr>
</table>
</body>
</html>";
$header="";
$header = "From: Tivoli <tivoli#inps.it>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$to= 'f.gatta#man-con.com';
$res=mail($to,$subject,$out,$header);
($res)?TRACE("Mail inviata con successo"):TRACE("Errore invio mail");
TRACE("END");
?\>
The called script (titled "confronti_itcam_DataPower.php") in the require function has the following code:
\<?php
$data=array();
$temp=array("Request_SI"=>0,"Request_ReqID"=>0,"Fault_SI"=>0,"Fault_FLT"=>0,);
function Executequery($q,$type)
{
global $data;
global $conn;
global $temp;
$resultset=$conn->query($q);
if(!$resultset)
{
TRACE("Errore esecuzione query $type :" . $conn->errorMsg);
die();
}
while($row_object=$conn->fetch($resultset))
{
(!isset($data[$row_object['Server']]))?$data[$row_object['Server']]=$temp:'';
$data[$row_object['Server']][$type]=(($row_object['value']!="")?$row_object['value']:'');
}
}
//COSTRUZIONE TABELLA PER AMBIENTE DATAPOWER
function create_table()
{
global $data;
$keys=array_keys($data);
$styleTB="style='font-family:arial;background-color:#1a0da8;margin:3px 0pt 15px;font-size: 9pt;width: 100%;text-align: center;'";
$styleTHfirst="style='color:#f7fafa;background-color:#1a0da8;border:1px solid #FFF;padding:4px;font-size:18px;font-weight:bold;'";
$styleTHsecond="style='background-color:#d5eded;border:1px solid #FFF;padding:4px;font-size:15px;font-weight:bold;font-style:italic;'";
$styleTD="style='color:#3D3D3D;padding:4px;background-color:#FFF;vertical-align:top;'";
$rowTable="";
foreach($keys as $key)
{
$_Request_SI=$data[$key]['Request_SI'];
$_Request_ReqID=$data[$key]['Request_ReqID'];
$scostRequest=$_Request_SI-$_Request_ReqID;
//$scostRequestPerc=(($_Request_SI==0 && $_Request_ReqID==0)?"Nessuno":(($_Request_SI==0)?"100 %":number_format((($scostRequest/$_Request_SI)*100),2)." %"));
$_Fault_SI=$data[$key]['Fault_SI'];
$_Fault_FLT=$data[$key]['Fault_FLT'];
$scostFault=$_Fault_SI-$_Fault_FLT;
//$scostFaultPerc=(($_Fault_FLT==0 && $_Fault_SI==0)?"Nessuno":(($_Fault_SI==0)?"100 %":number_format((($scostFault/$_Fault_SI)*100),2)." %"));
$rowTable.="<tr>
<td $styleTD align=center >
<b>$key</b>
</td>
<td $styleTD align=center >
$_Request_SI
</td>
<td $styleTD align=center >
$_Request_ReqID
</td>
<td $styleTD align=center>
$scostRequest
</td>
<td $styleTD align=center >
$_Fault_SI
</td>
<td $styleTD align=center >
$_Fault_FLT
</td>
<td $styleTD align=center >
$scostFault
</td>
</tr>";
}
$table_confronti="<table $styleTB id='table_confronti' style='width:100%'>
<thead>
<th $styleTHfirst colspan=7 align=center >
Ambiente DataPower
</th>
</thead>
<tbody>
<tr>
<td $styleTHsecond align=center>
Server
</td>
<td $styleTHsecond align=center >
Request su SI
</td>
<td $styleTHsecond align=center >
Request su SI_ReqID
</td>
<td $styleTHsecond align=center >
Δ request
<td $styleTHsecond align=center>
Fault su SI
</td>
<td $styleTHsecond align=center >
Fault su FLT
</td>
<td $styleTHsecond align=center >
Δ fault
</td>
</tr>
$rowTable
</tbody>
</table>";
$tb=" <center>
<table style='width:100%'>
<tr>
<td>
<div >".$table_confronti."</div>
</td>
</tr>
</table>
</center>";
return $tb;
}
$yesterday_inf_sol= "1".substr(date('Ymd',strtotime("-2 days")),2)."230000000";
$yesterday_sup_sol= "1".substr(date('Ymd',strtotime("-1 days")),2)."230000000";
$yesterday_inf_leg= "1".substr(date('Ymd',strtotime("-2 days")),2)."220000000";
$yesterday_sup_leg= "1".substr(date('Ymd',strtotime("-1 days")),2)."220000000";
$query_SI_request='select
upper(substr("Origin_Node",13,17)) as "Server",
sum("Request_Count") as "value"
from
"Services_Inventory_610"
where
upper(substr("Local_Hostname_U",1,9))=\'CUSTMON03\' and "Service_Type"=1 and
CASE
WHEN "TMZDIFF"=\'-3600\' THEN ("Interval_Begin_Time">=\''.$yesterday_inf_sol.'\' and "Interval_Begin_Time"<\''.$yesterday_sup_sol.'\')
WHEN "TMZDIFF"=\'-7200\' THEN ("Interval_Begin_Time">=\''.$yesterday_inf_leg.'\' and "Interval_Begin_Time"<\''.$yesterday_sup_leg.'\')
END
group by upper(substr("Origin_Node",13,17))';
$query_ReqID='select
upper(substr("Origin_Node",13,17)) as "Server",
sum("Request_Count") as "value"
from
"Services_Inventory_ReqID_610"
where
upper(substr("Local_Hostname_U",1,9))=\'CUSTMON03\' and
CASE
WHEN "TMZDIFF"=\'-3600\' THEN ("Interval_Begin_Time">=\''.$yesterday_inf_sol.'\' and "Interval_Begin_Time"<\''.$yesterday_sup_sol.'\')
WHEN "TMZDIFF"=\'-7200\' THEN ("Interval_Begin_Time">=\''.$yesterday_inf_leg.'\' and "Interval_Begin_Time"<\''.$yesterday_sup_leg.'\')
END
group by upper(substr("Origin_Node",13,17))';
$query_SI_fault='select
sum("Fault_Count") as "value",
upper(substr("Origin_Node",13,17)) as "Server"
from
"Services_Inventory_610"
where upper(substr("Local_Hostname_U",1,9))=\'CUSTMON03\' and
CASE
WHEN "TMZDIFF"=\'-3600\' THEN ("Interval_Begin_Time">=\''.$yesterday_inf_sol.'\' and "Interval_Begin_Time"<\''.$yesterday_sup_sol.'\')
WHEN "TMZDIFF"=\'-7200\' THEN ("Interval_Begin_Time">=\''.$yesterday_inf_leg.'\' and "Interval_Begin_Time"<\''.$yesterday_sup_leg.'\')
END
group by upper(substr("Origin_Node",13,17)) ';
$query_FLT='select
count(*) as "value",
upper(substr("Origin_Node",13,17)) as "Server"
from
"Fault_Log_Table_610"
where upper(substr("Hostname_U",1,9))=\'CUSTMON03\' and
CASE
WHEN "TMZDIFF"=\'-3600\' THEN ("Message_Time">=\''.$yesterday_inf_sol.'\' and "Message_Time"<\''.$yesterday_sup_sol.'\')
WHEN "TMZDIFF"=\'-7200\' THEN ("Message_Time">=\''.$yesterday_inf_leg.'\' and "Message_Time"<\''.$yesterday_sup_leg.'\')
END
group by upper(substr("Origin_Node",13,17)) ';
Executequery($query_SI_request,'Request_SI');
Executequery($query_ReqID,'Request_ReqID');
Executequery($query_SI_fault,'Fault_SI');
Executequery($query_FLT,'Fault_FLT');
$result=create_table();
?\>
What I got when all the code was in one script is a table with data after the variable $spiegazione, now after the splitting I get "1" in place of the table after $spiegazione.
Where am I wrong?

Related

How to export this table of data to Excel file from php

can anyone here help with the code to export to an Excel file i hope that someone can because I already have an export button.
I want to keep the most with this code because this code works well. and if you want to see the export.php ask for it.
here a picture
enter image description here
<a class="btn btnx btn-orange" href="export.php" target="_new"><i class="fa fa-download"></i> Export to Excel</a>
<div class="table-responsive">
<table id="mytable" class="table table-bordred table-striped">
<thead>
<tr>
<th>#</th>
<th>Auditeur</th>
<th>Afdeling</th>
<th>Invoerdatum</th>
<th>Week</th>
<th>Zone</th>
<th>Stand</th>
<th>Zijn alle overbodeige gereedschappen / materialen van de werkpost verwijderd / geïdentificeerd? ( sleutel, bouten / moeren,.... )</th>
<th>Opgeslagen foto nr1</th>
<th>Is er rommel aanwezig op de werkpost ( bekertjes, kledij, flesjes,....)</th>
<th>Opgeslagen foto nr2</th>
<th>Zijn vervallen / niet geautoriseerde documenten verwijderd?</th>
<th>Opgeslagen foto nr3</th>
<th>Opmerking</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$fetchdata=new DB_con();
$sql=$fetchdata->fetchdata();
$cnt=1;
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo htmlentities($cnt);?></td>
<td><?php echo htmlentities($row['Auditeur']);?></td>
<td><?php echo htmlentities($row['Afdeling']);?></td>
<td><?php echo htmlentities($row['PostingDate']);?></td>
<td><?php echo htmlentities($row['Week']);?></td>
<td><?php echo htmlentities($row['Zone']);?></td>
<td><?php echo htmlentities($row['Stand']);?></td>
<td><?php echo htmlentities($row['NOKOK01']);?></td>
<td><?php echo htmlentities($row['Results']);?></td>
<td><?php echo htmlentities($row['NOKOK02']);?></td>
<td><?php echo htmlentities($row['Results2']);?></td>
<td><?php echo htmlentities($row['NOKOK03']);?></td>
<td><?php echo htmlentities($row['Results3']);?></td>
<td><?php echo htmlentities($row['Bericht']);?></td>
<td><button class="btn btn-info btn-xs"><span class="glyphicon glyphicon-pencil"></span></button></td>
<td><button class="btn btn-danger btn-xs" onclick="return confirm('Wil je bestand echt verwijderen?');"><span class="glyphicon glyphicon-trash"></span></button></td>
</tr>
<?php
// for serial number increment
$cnt++;
}
?>
</tbody>
</table>
here is my export.php code
<?php
//export.php
$connect = mysqli_connect("localhost", "root", "", "oopscrud02");
$output = '';
if(isset($_POST["export"]))
{
$query = "SELECT * FROM tblusers";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<table class="table" bordered="1">
<tr>
<th>#</th>
<th>Afdeling</th>
<th>Invoerdatum</th>
<th>Week</th>
<th>Zone</th>
<th>Stand</th>
<th>Zijn alle overbodeige gereedschappen / materialen van de werkpost verwijderd / geïdentificeerd? ( sleutel, bouten / moeren,.... )</th>
<th>Opgeslagen foto nr1</th>
<th>Is er rommel aanwezig op de werkpost ( bekertjes, kledij, flesjes,....)</th>
<th>Opgeslagen foto nr2</th>
<th>Zijn vervallen / niet geautoriseerde documenten verwijderd?</th>
<th>Opgeslagen foto nr3</th>
<th>Opmerking</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["Auditeur"].'</td>
<td>'.$row["Afdeling"].'</td>
<td>'.$row["PostingDate"].'</td>
<td>'.$row["Week"].'</td>
<td>'.$row["Zone"].'</td>
<td>'.$row["Stand"].'</td>
<td>'.$row["NOKOK01"].'</td>
<td>'.$row["Results"].'</td>
<td>'.$row["NOKOK02"].'</td>
<td>'.$row["Results2"].'</td>
<td>'.$row["NOKOK03"].'</td>
<td>'.$row["Results3"].'</td>
<td>'.$row["Bericht"].'</td>
</tr>
';
}
$output .= '</table>';
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=Sorterend form.xls');
echo $output;
}
}
?>
I suggest you to use javascript library, it work for me
Install excell javascript and FileSaver for saving file
Adding 2 library
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js"></script>
XLX Js
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.1/xlsx.full.min.js"></script>
The script
<script>
$('#download-btn').on('click', function(){
var wb = XLSX.utils.table_to_book(document.getElementById('my-table'),{sheet: "Sheet name"})
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: true, type: 'binary'});
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i < s.length; i++) {
view[i] = s.charCodeAt(i) & 0xFF;
}
return buf;
}
saveAs(new Blob([s2ab(wbout)], {type:"application/octet-stream"}), 'test.xlsx');
})
</script>
Maybe the easiest way is to use DataTables.
See example: https://datatables.net/extensions/buttons/examples/initialisation/export.html
After that you can simply use css and make it look as you want.

double request only specting one

I have a webhooks that i use in someone shop's for Shopify, but only this use the information to upload to my server.
When the owner of the shop is click on fullfil item the order going to my site, but in some cases the order appear two times only with one click, i am using php and curl.
this is my php file
<?php
//start a session
session_start();
//Webhook enviado por shopify
$webhookContent= "";
$webhook= fopen('php://input' , 'rb');
while (!feof($webhook)) {
$webhookContent .= fread($webhook, 4096);
}
fclose($webhook);
$data= json_decode($webhookContent,true);
//guardar datos ordenes
$file = 'shipping_innata.txt';
$print = print_r($webhookContent, true);
file_put_contents($file, $print, FILE_APPEND | LOCK_EX);
//obtener desde headers el dominio de shopify
$domain_header= $_SERVER['HTTP_X_SHOPIFY_SHOP_DOMAIN'];
//consulta en base 99min
$db = mysqli_connect("localhost", "root", "plas711", "minut_api");
//comprobar carrier
$shipping= $data ['shipping_lines']['0']['code'];
$express= '99minutos.com en menos de 99 minutos (L-V de 9 a 16 hrs) SOLO DF';
$program= '99minutos.com Programado mismo día (L-V de 9 a 16 hrs) SOLO DF';
//variables obtenidas desde json
$first_name= $data['shipping_address']['first_name'];
$last_name= $data['shipping_address']['last_name'];
$email= $data['email'];
$phone= $data['shipping_address']['phone'];
$address1= $data['shipping_address']['address1'];
$address2= $data['shipping_address']['address2'];
$province= $data['shipping_address']['province'];
$zip= $data['shipping_address']['zip'];
$city= $data['shipping_address']['city'];
$latitude= $data['shipping_address']['latitude'];
$longitude= $data['shipping_address']['longitude'];
$note= $data['note'];
$name= 'Orden: '.$data['name'];
$pago= $data['gateway'];
if($pago =="Pago contra entrega (SOLO DF Y AREA METROPOLITANA)"){
$total_price= $data['total_price'];
}
else{
$total_price=0;
}
//busqueda del correo del propietario de la tienda en base de datos
$mail_db= "SELECT * FROM tbl_usersettings WHERE store_name = '$domain_header'";
$mail_result= mysqli_query($db, $mail_db);
$mail_q= mysqli_fetch_array($mail_result, MYSQLI_ASSOC);
$mail_str= $mail_q['email'];
////////////////////////////////////////////////////
//url encode para producto en bodegas
function request()
{
global $total_price,$pago,$latitude, $longitude, $address1, $address2, $city, $province, $zip, $email, $phone, $first_name, $last_name, $productos, $name, $db, $shipping, $express, $program;
// variables
$api_key= '23894thfpoiq10fapo93fmapo';
$user_id= '4290583552';
if ($shipping == $express){
$delivery_type = '99minutos';
}
else if($shipping == $program){
$delivery_type = 'Programado';
}
$latlng= '19.346857%2C-99.2985648';
$destination_route= urlencode(implode(' ', array($address1,$address2)));
$destination_locality= urlencode($city);
$destination_administrative_area_level= urlencode($province);
$destination_postal_code= urlencode($zip);
$d_latlng= urlencode(implode(',', array($latitude,$longitude)));
$customer_phone= urlencode($phone);
$nombre = 'Cliente: '.implode(' ',array($first_name,$last_name));
//Variable que pasa al sistema de 99minutos los datos en la seccion de notas
//$notes=urlencode(implode(', ', array($name,$nombre)));
//url que sirve para hacer la peticion de envion al sistema de 99minutos
$request = "https://das-dot-line-76299minutos.appspot.com/2/delivery/request?";
$request.= "api_key=".$api_key."&";
$request.= "user_id=".$user_id."&";
$request.= "delivery_type=".$delivery_type."&";
$request.= "route=ARTEAGA+Y+SALAZAR&";
$request.= "street_number=108&";
$request.= "neighborhood=Contadero&";
$request.= "locality=Mexico&";
$request.= "administrative_area_level_1=Distrito+Federal&";
$request.= "postal_code=05500&";
$request.= "country=Mexico&latlng=".$latlng."&";
$request.= "destination-route=".$destination_route."&";
$request.= "destination-street_number=&";
$request.= "destination-neighborhood=&";
$request.= "destination-locality=".$destination_locality."&";
$request.= "destination-administrative_area_level=".$destination_administrative_area_level."&";
$request.= "destination-postal_code=".$destination_postal_code."&";
$request.= "destination-country=Mexico&";
$request.= "destination-latlng=".$d_latlng."&";
$request.= "customer_email=".$email."&";
$request.= "customer_phone=".$customer_phone."&";
$request.= "notification_email=&";
if($pago =="Pago contra entrega (SOLO DF Y AREA METROPOLITANA)"){
$monto = "Cobro:".$total_price;
$notes = urlencode((implode(',', array($name,$nombre,$monto))));
$request.= "notes=".$notes."&";
$request.= "receivable_order=true&";
$request.= "amount=".$total_price."&";
}
else
{
$notes = urlencode((implode(',', array($name,$nombre))));
$request.= "notes=".$notes."&";
}
$request.= "dispatch=true";
//funcion curl para enviar la peticion de envio al sistema de 99minutos
$archivo = 'respaldo_innata.txt';
$texto = print_r($request, true);
file_put_contents($archivo, $texto, FILE_APPEND | LOCK_EX);
error_log("Request");
error_log(print_r($request, true));
$ch_request=curl_init();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $request);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);
curl_close ($curl);
error_log("Response");
error_log(print_r($response, TRUE));
die();
}
///////////////////////////////////////////////////
function mailprogramado()
{
global $domain_header, $name, $first_name, $last_name, $email, $phone, $address1, $address2, $province, $zip, $latitude, $longitude, $productos, $pago;
$to = "ens#99minutos.com";
$subject = "Envio Tienda Malabares";
$mail_body = '<html>';
$mail_body .='<body topmargin="25">';
$mail_body .='<h2> Dirección de Envio</h2>';
$mail_body .='<table width="500" border="1" cellspacing="10" cellpadding="10">';
$mail_body .='<tr> <td width="100" align="center"> Tienda: </td> <td align="left"> '. $domain_header .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Orden: </td> <td align="left"> '. $name .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Nombre: </td> <td align="left"> '. $first_name .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Apellidos: </td> <td align="left"> '. $last_name .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Correo: </td> <td align="left"> '. $email .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Teléfono: </td> <td align="left"> '. $phone .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Dirección: </td> <td align="left"> '. $address1 .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Dirección: </td> <td align="left"> '. $address2 .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Estado: </td> <td align="left"> '. $province .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Codigo Postal: </td> <td align="left"> '. $zip .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Latitud: </td> <td align="left"> '. $latitude .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Longitud: </td> <td align="left"> '. $longitude .' </td> </tr>';
$mail_body .='<tr> <td width="100" align="center"> Metodo de pago: </td> <td align="left"> '. $pago .' </td> </tr>';
$mail_body .='</table>';
$mail_body .='</body>';
$mail_body .='</html>';
$headers = "From:ens#99minutos.com\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $mail_body, $headers);
}
// error_log(print_r($data, true));
if($shipping == $express){
//Notificacion envio depar
mailprogramado();
//realizar pedido de envio
request();
//destruir sesion
session_destroy();
exit();
}
else if($shipping == $program){
//Notificacion envio depar
mailprogramado();
//realizar pedido de envio
request();
//destruir sesion
session_destroy();
exit();
}
?>
If I understand you correctly, you're wondering why do you get several requests from Shopify instead of just one.
I've faced the same problem recently, and I think it's a feature of Webhooks mechanism you have to deal with.
Consider this post: https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/webhook-url-is-called-between-2-4-times-220007
Bottomline. You should expect Shopify will hit your endpoint more than once and you have to manage this by yourself to avoid duplicating entities and stuff.

Hostgator cron job not working with this script

So I've been trying to use the Cron Job Manager at Hostgator, I select the php file and it should execute when sheduled. If i want to run the script manually, then I'd write http://thesitename.com/myfile.php and would execute, in this case, I'm sending PDFs to an email. Please check my code and see if I'm doing something wrong:
<?php
define('WP_USE_THEMES', true);
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
set_time_limit(0);
ignore_user_abort(1);
$args = array(
'post_type' => 'inversion',
'orderby' => 'meta_value_num',
'meta_key' => 'numero_de_ordenamiento',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'inversionista'
)
)
);
$the_query = new WP_Query( $args );
$current_posts = $the_query->get_posts();
print_r($current_posts);
foreach ($current_posts as $post)
{
$post_id = $post->ID;
$inversion = get_post($post_id);
$eluser = get_field('inversionista',$post_id);
$numconf=get_field('numero_de_cliente', 'user_'.$eluser['ID']);
$numord = get_field('numero_de_ordenamiento',$post_id);
ob_start(); ?>
<section class="wrap">
<img src="<?php bloginfo('template_directory');?>/images/CherryV.jpg" width="20%" alt="Site Logo">
<img style="float:right;" src="<?php bloginfo('template_directory');?>/images/info.jpg" width="45%" alt="Site Logo">
</section>
<br>
Logout
<br>
<h3 style="color:red;"><u>Estado de movimientos <?php $month = date(m);
if($month==1)
{
$elmes = "Enero";
}elseif($month==2){
$elmes = "Febrero";
}elseif($month==3){
$elmes = "Marzo";
}elseif($month==4){
$elmes = "Abril";
}elseif($month==5){
$elmes = "Mayo";
}elseif($month==6){
$elmes = "Junio";
}elseif($month==7){
$elmes = "Julio";
}elseif($month==8){
$elmes = "Agosto";
}elseif($month==9){
$elmes = "Septiembre";
}elseif($month==10){
$elmes = "Octubre";
}elseif($month==11){
$elmes = "Noviembre";
}elseif($month==12){
$elmes = "Diciembre";
}
echo $elmes;
echo " ";
echo date(Y); ?></u></h3>
<h3>Cliente confidencial: <?php echo $numconf; ?> </h3>
<h3>Movimientos correspondientes al periodo: 1 al 31 de <?php echo $elmes ." ".date(Y); ?></h3>
<br>
<div id="customers">
<table class="tabla" autosize="1" cellpadding="0" cellspacing="0" width="100%" border="1">
<thead>
<tr>
<td>
<h3 class="table2" >Periodo de Inversión</h3>
</td>
<td>
<h3 class="table2">Saldo Inicial</h3>
</td>
<td>
<h3 class="table2" >Inversión en el Periodo</h3>
</td>
<td>
<h3 class="table2" >Interés Causado en el Periodo</h3>
</td>
<td>
<h3 class="table2" >Intereses Pagados</h3>
</td>
<td>
<h3 class="table2" >Intereses Reinvertidos</h3>
</td>
<td>
<h3 class="table2" >Saldo Final</h3>
</td>
</tr>
</thead>
<tbody>
<?php
$igalf = 0;
if( have_rows('datos_especificos') ):
?>
<?php
$highest = 0;
$arraycount=0;
$thearrayking = array();
$arrayinsert = array();
while ( have_rows('datos_especificos') ) : the_row();
$icelpx = get_sub_field('interes_causado_en_el_periodo',$post_id);
$cpx = get_sub_field('cantidad_pagada',$post_id);
$crx = get_sub_field('cantidad_reinvertida',$post_id);
$sal1x = get_sub_field('saldo',$post_id);
$ipx = get_sub_field('inversion_en_el_periodo',$post_id);
$sal2x = get_sub_field('saldo_final',$post_id);
$fech = get_sub_field('fecha',$post_id);
$fecharray0 = substr($fech,0,4);
$fecharray1 = substr($fech,4,2);
$fecharray = $fecharray1."/".$fecharray0;
$sal1 = get_sub_field('saldo',$post_id);
$ielp = get_sub_field('inversion_en_el_periodo',$post_id);
$icelp = get_sub_field('interes_causado_en_el_periodo',$post_id);
$cp = get_sub_field('cantidad_pagada',$post_id);
$elsf2 = get_sub_field('saldo_final',$post_id);
$cr = get_sub_field('cantidad_reinvertida',$post_id);
$crt = $crt+$cr;
$sal2 = get_sub_field('saldo_final',$post_id);
$igalf = $igalf+$icelp;
$fech2 = $fech+100;
$ID= $the_query->ID;
if($highest<$elsf2)
{
$highest = $elsf2;
}
$arrayinsert = array($fecharray, $elsf2);
array_push($thearrayking, $arrayinsert);
$arraycount = $arraycount+1;
$fechstring="$fech";
$part1=substr("$fechstring", 0, 4);
$part2=substr("$fechstring", 4, 2);
$part3=substr("$fechstring", 6,2);
//$date = DateTime::createFromFormat('Ymd', $retrieved); ?>
<tr>
<td>
<p class="table" style="text-align:center;"> <?php echo $part3."/".$part2."/".$part1; ?> </p>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format($sal1,2); ?> </p>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format($ielp,2); ?> </p>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format($icelp,2); ?> </p>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format($cp,2); ?> </p>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format($crx,2); ?> </p>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format($sal2x,2); ?> </p>
</td>
</tr>
<?php
endwhile;
else :
// no rows found
endif;
?>
</tbody>
</table>
</div>
<br>
<br>
<h1>Resumen de Inversión</h1>
<br>
<table autosize="5">
<?php
$fech7 = $fech + 100;
$ptest = substr($fech7,4,2);
if($ptest==12)
{
$fech7=$fech7-1200+10000;
}
$fechstringxx = $fech7;
$part1x=substr("$fechstringxx", 0, 4);
$part2x=substr("$fechstringxx", 4, 2);
$part3x=substr("$fechstringxx", 6, 2);
// $date2 = DateTime::createFromFormat('Ymd', $retrieved2); ?>
<tr>
<td>
<h3 class="table2" style="text-align:center;"> Saldo Inicial <?php echo $part3."/".$part2."/".$part1; ?> </h3>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $sal1,2); ?> </p>
</td>
</tr>
<tr>
<td>
<h3 class="table2" style="text-align:center;"> Nuevas Inversiones </h3>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $ielp,2); ?> </p>
</td>
</tr>
<tr>
<td>
<h3 class="table2" style="text-align:center;"> Intereses Pagados </h3>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $cp,2); ?> </p>
</td>
</tr>
<tr>
<td>
<h3 class="table2" style="text-align:center;"> Intereses Reinvertidos </h3>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $crx,2); ?> </p>
</td>
</tr>
<tr>
<td>
<h3 class="table2" style="text-align:center;"> Total Intereses Generados a la fecha</h3>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $igalf,2); ?> </p>
</td>
</tr>
<tr>
<td>
<h3 class="table2" style="text-align:center;"> Saldo Final <?php echo $part3x."/".$part2x."/".$part1x; ?> </h3>
</td>
<td>
<p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $sal2,2); ?> </p>
</td>
</tr>
</table>
<?php $tableVar = ob_get_contents();
$numord2 = str_replace(".","-",$numord);
$correo = $current_user->user_email;
// echo $correo;
$mpdf = new mPDF('c');
$stylesheet = file_get_contents(get_template_directory_uri() . '/table.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($tableVar,2);
$mpdf->Output('test24.pdf','F');
$content = $mpdf->Output('', 'S');
$content = chunk_split(base64_encode($content));
$mailto = $correo; //Mailto here
$from_name = 'Cherry'; //Name of sender mail
$from_mail = '9#gmail.com'; //Mailfrom here
$subject = 'Reporte De Inversion'.$numord;
$message = 'Hola te mando tu reporte de inversion';
$filename = "Reporte-De-Inversiones-".date("m-Y",time())." ".$numord2; //Your Filename whit local date and time
//Headers of PDF and e-mail
$boundary = "XYZ-" . date("dmYis") . "-ZYX";
$header = "--$boundary\r\n";
$header .= "Content-Transfer-Encoding: 8bits\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n"; //plain
$header .= "$message\r\n";
$header .= "--$boundary\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n\r\n";
$header .= "$content\r\n";
$header .= "--$boundary--\r\n";
$header2 = "MIME-Version: 1.0\r\n";
$header2 .= "From: ".$from_name." \r\n";
$header2 .= "Return-Path: $from_mail\r\n";
$header2 .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header2 .= "$boundary\r\n";
$bob = "bobsemail#email.com";
//$sended = mail($mailto,$subject,$header,$header2, "-r".$from_mail);
$sended2 = mail($bob,$subject,$header,$header2, "-r".$from_mail);
//echo($sended);
echo($sended2);
$mpdf->Output($filename ,'F');
}
?>
Before all: Hostgator doesn't allow Crons running with a difference of under 15 minutes, you can read that information here. If that is your case, your problem is solved.
Now there are two ways of solving your problem:
1. Fix the cron and run the script (the wrong or at least, the incorrect way, I'll explain below):
You need to give read and write access to the file so the system can run it. Try 777 for debugging.
If it's not working, please edit the OP with the cron instruction so we can debug it.
It should look something like the example below, Hostgator give you information on how it should look here:
/opt/php55/bin/php /home/username/public_html/cron.php
Hostgator provides information about Crons here, about cURL here and there's someone complaining about the same thing in their forums here.
Somewhere in your /home/ folder should be a file called cron.errors.log, you can find there relevant information, for sure.
I'm pretty sure your problem is related with the include path.
I say this is the incorrect way because you're using Wordpress and in that case you should use native WP core function in order to make your script work, particularly by doing a plugin and using wp_schedule_event()
2. The correct way to do it - Plugin + wp_schedule_event();
Transform your script into a plugin. This way there's no need to include the wp-blog-header.php to access the functions and things will work much more integrated.
Here's a quick tutorial on how to do a plugin and you can access information about wp_schedule_event in the Wordpress page about it.
Basically, should look something like this:
register_activation_hook( __FILE__, 'prefix_activation' );
/**
* On activation, set a time, frequency and name of an action hook to be scheduled.
*/
function prefix_activation() {
wp_schedule_event( time(), 'hourly', 'prefix_hourly_event_hook' );
}
add_action( 'prefix_hourly_event_hook', 'prefix_do_this_hourly' );
/**
* On the scheduled action hook, run the function.
*/
function prefix_do_this_hourly() {
// do something every hour
}
But there's a catch: the scheduled event only runs if the site has visitors. It's not the best behavior but is what we have available.
This way you'll be free of Hostgator and can have a cool plugin that is perfectly integrated with your system.

Mail message and attachment in php

Im trying to send a mail attachment in php.
Here is the code which im trying but dont know whats wrong in this:
please can anyone suggest any modification for the following code
<?php
$path = "files/";
$files = "myfile.csv";
$par_mailto = "RECEIVER MAIL ID";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
$file = fopen($path.$files,"rb");
$data = fread($file,filesize($path.$files));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
//mail attachment ends
$date = date_default_timezone_set('Asia/Kolkata');
$today = date("F j, Y, g:i a T");
$subject = "Test mail on ".$today ;
$header .= 'MIME-Version: 1.0' . "\r\n". 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = $header."From: info#ziddu.com ". "\r\n"
. "Cc: $par_mailcc" . "\r\n";
//!!!All the emails are coming with comma as separator .... "\r\n\" is important to separate FROM Cc BCc.
$message .= "<html><body>";
//
$message .= "<table width='800' cellspacing='5' cellpadding='5' border='0' align='center' style='border:1px solid #e6e6e6'>
<tbody><tr>
<td height='80' bgcolor='#F3F3F3' style='padding-left:15px'><table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tbody><tr>
<td width='50%' align='center'></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td valign='top' height='150'>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>Dear Mr. ".$_SESSION['name'].",</p>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>This is the test mail with an attachment</b></p>
";
$message .= "
<div style='width:584px;background-color:#ffffff;border:#e8e7e7 solid 1px;padding:27px 0;margin:0 auto;border-bottom:0'>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:0px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='400px'> <span style='color:#333333;font-weight:600'>Transaction Details: </span></td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Transfered </td>
<td>USD 10000</td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Fee</td>
<td>USD 200</td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Total</td>
<td>USD 4000</td>
</tr>
</tbody>
</table>
</div>
<div style='font:normal 12px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 0px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
</tbody>
</table>
</div>
</div>
<div style='margin:0 auto;width:594px'><img alt='' src='https://ci4.googleusercontent.com/proxy/Rku_qr-ooNg8yw1tsELcIxO6HBPXzNZtY_bfb9r8yySSxzteTaIxDoJ83pE5XmtwvZO7O5UC4wM31f_rVlP6HyR9VK2OrStgu8llNx45_L81Jv7YD6P1=s0-d-e1-ft#https://dx87hk8eoofvk.cloudfront.net/images/email/receiptedge.png' title=''></div>";
$message .="<p style='font-family:verdana'><br><b>IMPORTANT:</b>"
. " Please do not reply to this message or mail address. For any queries,please mail to info#ziddu.com \n\n</p>";
$message .="<p style='font-family:verdana'><b>DISCLAIMER:</b>"
. " This communication is confidential and privileged and is directed to and for the use of the addressee only. "
. "The recipient if not the addressee should not use this message if erroneously received, "
. "and access and use of this e-mail in any manner by anyone other than the addressee is unauthorized. "
. "The recipient acknowledges that Ziddu.com may be unable to exercise control or ensure or guarantee the "
. "integrity of the text of the email message and the text is not warranted as to completeness and accuracy. "
. "\n\n</p><br>";
$message .="<p style='font-family:verdana'>Regards,<br>Ziddu Team <br>www.ziddu.com \n\n</p>";
$message .="</td>
</tr>
<tr>
<td height='30' bgcolor='#E9E9E9' align='center'><strong>Upload.. Share.. Earn!</strong></td>
</tr>
</tbody></table>";
#mail($par_mailto, $subject, $message, $headers);
?>
As i need to add some more information with design and all also had an attachment that needs to be attached. Got confused where im gone wrong

How make a submit php that will send image (from user upload) via email?

I need help generating form to email, i'll try many outhere but no one matched i need. I have a form i've got from Bell Online Mailer, but this script doesnt allow image to send... So i modif a little form code and now i already had an upload form. And now what kind of function or php i mustly add to display it as an image (NOT ATTACHED) corectly inside the form message..
here is the code
<?php
/*
BELLonline PHP MAILER SCRIPT v1.5
Copyright 2006 Gavin Bell
http://www.bellonline.co.uk
gavin#bellonline.co.uk
Set up an email form on your website within minutes - see readme.txt for installation.
*/
extract($_POST);
if (!file_exists("config.php"))
{
$host = $_SERVER[HTTP_HOST ];
$path = pathinfo($_SERVER['PHP_SELF']); $file_path = $path['dirname']; print "<h1>BELLonline PHP mailer script</h1> <h2>There is a problem with your PHP mailer script installation</h2> <p>The config.php file seems to be missing!</p> <p>For this script to work, you need to upload the config.php file that came with the download of the BELLonline PHP mailer script.</p> <p>The file must be in the following directory of your website:</p> <p>$host<span style=\"font-weight: bold; font-size: 150%;\">$file_path/</span></p> <p>If you need help installing the script, then feel free to email me at gavin#bellonline.co.uk</p>"; exit; } include "config.php";
if ($sendto_email == "changeme#example.com") { print "<h1>BELLonline PHP mailer script</h1> <h2>Installation nearly complete!</h2> <p>Thank you for downloading the free PHP mailer script from BELLonline web services. </p> <p>To start using the script, open config.php in a text editor and change the <b>$sendto_email</b> variable to your email address.</p> <p>If you did not get a config.php file with this script, then go to the PHP mailer script page and download the full script.</p> <p>If you need help installing the script, then feel free to email me at gavin#bellonline.co.uk</p>"; exit; } if (empty ($senders_name)) { $error = "1"; $info_error .= $lang_noname . "<br>"; } if (empty ($senders_email)) { $error
= "1"; $info_error .= $lang_noemail . "<br>"; } if (empty ($mail_subject)) { $error = "1"; $info_error .= $lang_nosubject . "<br>"; } if (empty ($mail_message)) { $error = "1"; $info_error .= $lang_nomessage . "<br>"; } if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,6}$", $senders_email)) { $error = "1"; $info_error .= $lang_invalidemail . "<br>"; } if (empty ($security_code)) { $error = "1"; $info_error .= $lang_nocode . "<br>"; } elseif ($security_code != $randomness) { $error = "1"; $info_error .= $lang_wrongcode . "<br>"; } if ($showlink != "no") { $link = "<br><span style=\"font-size: 10px;\">Powered by BELLonline PHP mailer script</span>"; } if ($error == "1") { $info_notice = "<span style=\"color: " . $error_colour . "; font-weight: bold;\">" . $lang_error . "</span><br>"; if (empty ($submit)) { $info_error = ""; $info_notice = $lang_notice; }
function Random() { $chars = "ABCDEFGHJKLMNPQRSTUVWZYZ23456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 4) { $num = rand() % 32; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_code = Random(); $mail_message = stripslashes($mail_message);
print "<form name=\"BELLonline_email\" enctype=\"multipart/form-data\" method=\"post\" style=\"margin: 0;\" action=\"\"> <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
<tr align=\"$title_align\" valign=\"top\">
<td colspan=\"2\"><span style=\"$title_css\">$lang_title</span></td>
</tr>
<tr align=\"left\" valign=\"top\">
<td colspan=\"2\">$info_notice$info_error</td>
</tr>
<tr valign=\"top\">
<td align=\"right\">$lang_name</td>
<td align=\"left\"><input name=\"senders_name\" type=\"text\" class=\"mailform_input\" id=\"senders_name\" style=\"width: $input_width;\" value=\"$senders_name\" maxlength=\"32\"></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_youremail</td>
<td align=\"left\"><input name=\"senders_email\" type=\"text\" class=\"mailform_input\" id=\"senders_email\" style=\"width: $input_width;\" value=\"$senders_email\" maxlength=\"64\"></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_subject</td>
<td align=\"left\"><input name=\"mail_subject\" type=\"text\" class=\"mailform_input\" id=\"mail_subject\" style=\"width: $input_width;\" value=\"$mail_subject\" maxlength=\"64\"></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_message</td>
<td align=\"left\"><textarea name=\"mail_message\" cols=\"36\" rows=\"5\" style=\"width: $input_width;\" class=\"mailform_input\">$mail_message</textarea></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_image</td>
<td align=\"left\"><input name=\"mail_image\" size=\"10\" type=\"file\" class=\"mailform_input\" id=\"mail_image\" value=\"$mail_image\" maxlength=\"64\"></td>
</tr>
<tr align=\"left\" valign=\"top\">
<td width=\"100\">$lang_confirmation</td>
<td><input name=\"security_code\" type=\"text\" id=\"security_code\" size=\"5\">
<b>$random_code</b></td>
</tr>
<tr valign=\"top\">
<td colspan=\"2\" align=\"right\"><input name=\"randomness\" type=\"hidden\" id=\"randomness\" value=\"$random_code\">
<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"$lang_submit\" class=\"mailform_button\"></td>
</tr> </table> </form>"; } else {
if ($checkdomain == "yes") { $sender_domain = substr($senders_email, (strpos($senders_email, '#')) +1); $recipient_domain = substr($sendto_email, (strpos($sendto_email, '#')) +1); if ($sender_domain == $recipient_domain) { print "Sorry, you cannot send messages from this domain ($sender_domain)"; exit; } }
$info_notice = $lang_sent; $mail_message = stripslashes($mail_message); $mail_image = $_POST['mail_image']; $content = $mail_image . $mail_message . '<p> Oleh ' . $senders_name . ', hubungi ' . $senders_email . ' </p>'; $senders_email = preg_replace("/[^a-zA-Z0-9s.#-_]/", "-", $senders_email); $from = $senders_email; $senders_name = preg_replace("/[^a-zA-Z0-9s]/", " ", $senders_name); $headers = "From: $senders_name <$senders_email> \r\n"; $headers .= "X-Mailer: BELLonline.co.uk PHP mailer \r\n"; $result = sendmail($sendto_email, $mail_subject, $content, $from);
print " <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
<tr align=\"$title_align\" valign=\"top\">
<td colspan=\"2\"><span style=\"$title_css\">$lang_title</span></td>
</tr>
<tr align=\"$title_align\" valign=\"top\">
<td colspan=\"2\">$info_notice</td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_name</td>
<td align=\"left\"><b>$senders_name</b></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_youremail</td>
<td align=\"left\"><b>$senders_email</b></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_subject</td>
<td align=\"left\"><b>$mail_subject</b></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_message</td>
<td align=\"left\"><b>$mail_message</b></td>
</tr>
</table>";
}
//Simple mail function with HTML header
function sendmail($sendto_email, $mail_subject, $content, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($sendto_email, $mail_subject, $content, $headers);
if ($result) return 1;
else return 0;
}
?>
You can easily solve it using PHP upload or an image uploader (I'm using Plupload at the moment) and PHP Mailer to send the email. As you mentioned not to intend sending the image as an attachment, in PHP Mailer, you just have to set an html message with the image inside it.

Categories