View Single Post
  #1 (permalink)  
Old 04-13-05, 03: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
Reply With Quote