CGI Script Send Mail error - cgi

Hopefully someone can help a user that has zero experience with CGI coding. Prior to yesterday, the following code was working fine when our clients would submit their orders. Then yesterday an internal server error message would appear in their browser.
When our hosting company did some trouble shooting this is what their error log was saying:
20130508T200031: www.4printer.com/cgi-bin/mailit.cgi
open |/usr/lib/sendmail -t -oi -oem: Permission denied
at /home/users/web/b643/ipw.i4printe/public_html/cgi-bin/mailit.cgi line 110
Unfortunately they do not support coding issues.
Line 110 of the code just says this:
$msg->send();
This is the entire CGI code:
#!/usr/bin/perl
# webmaster#qnis.net
$date = `/bin/date`; chop($date);
# Read the Input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
#pairs = split(/&/, $buffer);
if(!($buffer =~ /CUSTOMER/)){
print <<"(ERROR_MSG)";
Content-type:text/html
<center><font size='4'><b>No data was recorded. Please use your browsers back button and try again.
(ERROR_MSG)
exit;
}
$mailprog = "/usr/sbin/sendmail";
$emailInfo = "";
open(MAIL, "|$mailprog -t") || do{ print "Can't open $mailprog!\n"; exit;};
print MAIL "To: ctsales2\#4printer.com\n";
# print MAIL "To: jim\#spiderbilt.com\n";
print MAIL "From: 4printWebForm\n";
print MAIL "Subject: California Financial Printing Order Form\n\n";
print MAIL "This form was submitted on $date\n\n";
foreach $pair (#pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($value eq "SUBMIT INFORMATION") {
Next;
} else {
print MAIL "$name: $value\n\n";
$emailInfo = $emailInfo . "$name: $value<br /><br />";
}
}
close (MAIL);
$title='Perl Mail demo';
$from= 'info#4printer.COM';
$rcvd_cookies = $ENV{'HTTP_COOKIE'};
#cookies = split /;/, $rcvd_cookies;
foreach $cookie ( #cookies ){
($key, $val) = split(/=/, $cookie); # splits on the first =.
$key =~ s/^\s+//;
$val =~ s/^\s+//;
$key =~ s/\s+$//;
$val =~ s/\s+$//;
if( $key eq "4printerEmail" ){
use URI::Escape;
$user_id = uri_unescape($val);
}
}
## Mail Header
use MIME::Lite;
# SendTo email id
# create a new MIME Lite based email
my $msg = MIME::Lite->new
(
Subject => "4Printer.com Confirmation",
From => 'sales#4printer.com',
To => $user_id,
Type => 'text/html',
Data => '
<tr>
<td align="left">
<div width="300">
<font face="Arial" size="2">
<p>
'.$emailInfo.'
</p>
<p>
Your order has been received and is being processed. <br /><br />
Thank you for your order!
</p>
<br />
<font color="#5485a3"><b>California Financial Printing</b></font><br />
P.O. Box 25755<br />
Fresno, CA 93729-5755<br />
559.454.8414<br />
800.438.1449
</font>
</div>
</td>
</tr>
</table>
</td>
</tr>
'
);
$msg->send();
print <<output;
Content-type:text/html
output
Any advice or input is greatly appreciated. I thank you in advance!

Related

Insert Multiple Rows in Laravel (Image Upload Issues)

In my application, I have faced several issues when I try to insert multiple rows of data into a database in laravel 8. Basically this issues is related to image upload. I have add related code to get help.
Controller View:
foreach($request->param_img as $key => $param_img){
$data = new PortfolioParam;
$data->param_desc = $request->param_desc[$key];
if($request->hasfile('param_img')){
$file = $request->file('param_img');
$extension = $file->getClientOriginalExtension();
$filename = time().'.'.$extension;
$file->move('upload/portfolio_param/', $filename);
$portfolio->param_img = $filename;
}
$data->portfolio_id = $portfolio->id;
$data->save();
}
Blade View:
<td class="pl-0 border-0">
<textarea class="form-control" name="param_desc[]" id="" cols="30" rows="3"></textarea>
</td>
<td class="border-0">
<input type="file" class="form-control" name="param_img[]">
</td>
Error
Call to a member function getClientOriginalExtension() on array
How can I get rid of this problems??
You have looped through the image but you have not used it in your image uploading code. You are still using the request data. Check this out, hopefully it helps.
// $file = $request->file('param_img');
$file = $param_img;
$extension = $file->getClientOriginalExtension();
$filename = time().'.'.$extension;
$file->move('upload/portfolio_param/', $filename);
$portfolio->param_img = $filename;

Notice: Undefined variable: on line 24

I have the code:
if(isset($_POST['id'])){ $res = $_POST['id']; }
if(isset($_POST['ora2'])){ $oratwo = $_POST['ora2']; }
$operator = $_SESSION['login'];
$order = "
UPDATE `frontdes_dep`.`flux_receptie`
SET `status_preluare` = 'ALOCAT', `ora_preluare` =$oratwo, `operator_preluare` =$operator
WHERE `flux_receptie`.`id` =$res";
$result = mysqli_query($connection, $order);
When I press the submit button which take actions above, it returns me error:
( ! ) Notice: Undefined variable: oratwo in C:\wamp\www\interfata_client.php on line 24
The code is working because when I look into DB, the columns populate with values.
Line 24 is the line with $order = ...
The submit is in an echo:
echo "<div id='example3'>
<form style='padding:15px 0px 0px 0px' id='interfata' name ='interfata' method='POST' action='interfata_client.php' enctype='multipart/form-data'>
<input type='hidden' name='id' value='$res[0]'>
<input type='hidden' name='ora2' value='now()'>
<input type='submit' name='name' value='ALOCARE'>
</form>
<td><center>preluat de:<p><b>$res[8]</center></b></td>
</tr>
</div>
<br>
";
Does anynone know what am I doing wrong? I have WAMP installed.
Thanks! :)
There are 2 ways to get rid of this issue , The first one is to ignore the issue by turning of Notice exceptions .
error_reporting(E_ALL ^ E_NOTICE );
Or try the second solution below.
Notice : check whether the value is coming up from the form ('ora2')
before trying the second one.
Your code
if(isset($_POST['ora2'])){ $oratwo = $_POST['ora2']; }
Updated code
if(isset($_POST['ora2'])){
$oratwo = isset($_POST['ora2']) ? $_POST['ora2'] : '';
}

Deleting single item with submit from database results in two ID's and strings

When I try and delete an entry from the code below it seems to spew out two array values with different index numbers and will not delete the entry. If I click multiple times it finally gets the correct ID but only by some random chance.
Using echo var_dump($deleted) results in something like:
String(2) "10"
String(1) "7"
These can vary and seems to be random.
I have reduced my whole plugin to just the code below thinking that maybe some other submit query might be interfering with it. And still I get two ID's with unknown string assignments.
Any ideas?
function myplugin_update_page(){
global $wpdb;
$update_page_list = $wpdb->get_results('SELECT * FROM wp_update_page');
$active = $wpdb->get_var("SELECT * FROM wp_update_page WHERE active='on'");
echo '<form method="post" action=""><table>';
foreach ( $update_page_list as $update ) { ?>
<tr>
<td><input type="image" src="<?php echo plugin_dir_url(__FILE__).'images/delete.png'; ?>" name="delete[]" value="<?php echo $update->ID; ?>" /></td>
</tr>
</table>
</form>
</div>
<?php
}
if(isset($_POST['delete'])) {
$delete = $_POST['delete'];
foreach ($delete as $deleted) {
$wpdb->query("DELETE FROM wp_update_page WHERE ID = $deleted");
}
echo "<script type='text/javascript'>window.location=document.location.href;</script>";
}
}

How can I connect my php code to MySQL database?

How can I connect my php code to MySQL database?
I have tried many times and it cannot access the database.
These are the codes in my php file:
<html>
<head>
<title>Brandon's Search Engine - Results</title>
</head>
<body>
<h2>Brandon's Search Engine</h2>
<form action='./search.php' method='get'>
<input type='text' name='k' size='80' value='<?php echo $_GET['k']; ?>' />
<input type='submit' value='Search' >
</form>
<hr />
<?php
$k = $_GET['k'];
$terms = explode(" ", $k);
$query = "SELECT * FROM search WHERE ";
foreach ($terms as $each){
$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= "OR keywords LIKE '%$each%' ";
}
// connect
mysql_connect("sql102.freezoy.com", "frzoy_13854016", "xxxx");
mysql_select_db("frzoy_13854016_search");
$query = mysql_query($query);
$numrows = $query->num_rows;
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query)){
$id = $row('id');
$title = $row('title');
$description = $row('description');
$keywords = $row('keywords');
$link = $row('link');
echo "<h2><a href='$link'>$title</a></h2>
$description<br /><br />";
}
}
else
echo"No results found for \"<b>$k</b>\"";
// disconnect
mysql_close();
?>
</body>
</html>
I have insert some data into the database.
Please help. Thanks in advance.

How to get include preg_match_all results in header location?

I have the following function written in function.php in a wordpress theme
function get_mms($my_post) {
$post_id = $my_post; //$_GET["p"];
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
preg_match_all('#\[mms\](.+)\[\/mms\]#', $queried_post->post_content, $matches);
echo 'EN: ' . $matches[1][0];
echo '<br><br><form action= " ' . get_permalink( $id ) . ' " method="post">
Numar: <input type="text" name="fname" />
<input name="submito" type="submit" />
</form>';
$numero = $_POST["fname"];
if(isset($_POST['submito'])&& $_POST['fname']){
$numero = $_POST["fname"];
header("Location: http://server/&to=$numero&text='.$matches[1][0].'&from=Moldcell");
}
When I submit the form instead of getting the value of $matches[1][0] I get Array[0].
Is there someting I did wrong? What can I do to make it grab the value of preg_match_all results?