Current location: Hot Scripts Forums » Programming Languages » Perl » converting perl script to php help!!


converting perl script to php help!!

Reply
  #1 (permalink)  
Old 04-13-05, 04:02 PM
macruddace macruddace is offline
New Member
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
converting perl script to php help!!

Hi,

I have just been notified by my host that I am not able to run perl scripts on my server just after i had paid a years non refundable hosting fee but as i had already bought my domain name their hosting with perl availability was for "brand new customers only!!". So i was wondering if any of u nice people could (if possible) could convert this perl script below into php. many thanks in advance.


#!/usr/local/bin/perl
#
# Mal's e-commerce
# Form to email processor
#
# This simple script is designed to take the
# remote HTTP link from the cart and send an email
# to the customer.
#
# Html e-mails added
# by Trent McCartney
#
#Just make up your own email.html file with all the code
#and variables for mals and put it in the cgi-bin
#do a chmod 755 and you should be all set!
#Currently the script is made to send a html to YOU not your CUSTOMER!
#please e-mail me (trentm@globalsoft.net if you have problems with this .. NOT MAL!
#Have Fun

$| = 1;

# Path to send mail instead by uncommenting this line
$SEND_MAIL="/usr/sbin/sendmail -t";

# The email's subject line
$subject1= "YOUR SUBJECT HERE";
$subject2= "New Online Order Posted";

# Your email address
# The backslash before the @ in the address is IMPORTANT!
$sender = "you\@yourdomain.com";


# This part takes the incomming query string and
# parses it into seperate fields with the names
# $Data{'field_name'}

@pairs = split(/&/, $ENV{'QUERY_STRING'});
# For each name-value pair:
foreach $pair (@pairs) {

# Split the pair up into individual variables.
local($name, $value) = split(/=/, $pair);

# Decode the form encoding on the name and value variables.
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

if ($value) {
$Data{$name} = $value;
}
}

# Output a header. We must do this!
print "Content-type: text/html\n\n";

# If there is no recipient for the message
# then stop here
if ( ! $Data{'email'} ) {
print "No sender email address";
exit;
}

# The cart is delimited by ~ between lines so
# replace these with a \n new line
$cart = "";
@lines = split(/~/, $Data{'cart'});
foreach $item (@lines) {
$cart .= $item . "\n";
}

# We build up the body of the messagefor the e-mail to the customer
$message1 = "\nThank you for your order $Data{'inv_name'}. Bellow is a summary of your purchase, as well as your order information.

Customer Id : $Data{'id'}
Date : $Data{'date'}
For payment by $Data{'method'}

Product , Quantity , Price
==========================
$cart

Discount : -$Data{'discount'}
Subtotal : $Data{'subtotal'}
Shipping : $Data{'shipping'}
Tax : $Data{'tax'}
-------------
TOTAL : $Data{'total'}

Invoice To:
$Data{'inv_name'}
$Data{'inv_addr1'}
$Data{'inv_addr2'}
$Data{'inv_state'}
$Data{'inv_zip'}
$Data{'inv_country'}
$Data{'tel'}
$Data{'fax'}
$Data{'email'}


If you have any questions about your order please do not hesitate
to contact us. You can reply to this email, or call us directly at your number.
";

# There are two extra fields that are not included in this sample
# they are Data{'message'} and Data{'ip'}.

# And this actually sends the email TO THE CUSTOMER
if ($SEND_MAIL ne "")
{
open (MAIL,"| $SEND_MAIL");

print MAIL "To: $Data{'email'}\n";
print MAIL "From: $sender\n";
print MAIL "Reply-to: $sender\n";
print MAIL "X-Mailer: Perl Powered Socket Mailer\n";
print MAIL "Subject: $subject1\n\n";
print MAIL "$message1";
print MAIL "\n.\n";

close(MAIL);
}
#This sends a html e-mail to YOU!!!!!
{
open (MAIL,"| $SEND_MAIL");
print MAIL "To: $Data{'email'}\n";
print MAIL "From: $sender\n";
print MAIL "Reply-to: $sender\n";
print MAIL "X-Mailer: Perl Powered Socket Mailer\n";
print MAIL "Subject: $subject2\n";
print MAIL "Content-Type: text/html; charset=\"us ascii\"\n";

open (HTML,"email.html") || die $!;

while(<HTML>){
print MAIL eval("qq($_)");
}
}
close(HTML);
close(MAIL);


# Confirmation - Dont' cut this off, it lets my server
# know that the transfer is finished
print "Success<br>Sent to $Data{'email'}\n";

# End of script!




kind regards

martin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-14-05, 03:38 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
You'll probably have better luck in the PHP forum. I'm not fluent enough in PHP to help you here myself. I do, however, find it very hard to believe a host won't support Perl unless maybe it's a Windows host.

~Charlie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 04:27 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
php executed in a perl script? -[OnTarget]- PHP 5 04-10-05 08:05 AM
Converting from Perl to PHP G-Money Perl 1 07-23-04 05:38 PM
Translate ASP to PHP and PERL POSERA ASP 0 06-12-04 02:12 AM


All times are GMT -5. The time now is 07:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.