Script collaboration? - perl checkout/Mime::Creator

Get help with nopcart Perl, PHP or ASP checkout related issues.

Moderators: Koibito, Stefko, Randy

Script collaboration? - perl checkout/Mime::Creator

Postby chueewowee » Thu Jan 10, 2008 10:22 pm

Hi,

I'm seeking collaboration in adjusting the perl checkout script to use MIme encodings, rather than
Code: Select all
$mailprogram = "/usr/bin/sendmail -t";


Because the native character set of email is 7-bit ASCII. If you want to use anything else, like British £ signs, you need to use MIME, declare the character set (usually UTF-8), and encode the UTF-8 chars into 7-bit ASCII (probably using quoted-printable).

There are various Perl modules to help with that, Email::MIME::Creator seems the best. http://search.cpan.org/~rjbs/Email-MIME-Creator/lib/Email/MIME/Creator.pm

I'm using the Kamya Perl script and need to rewrite it with specific Mime::Creator instructions, with various if clauses.

Here's a basic single part Mime::Creator script which works:

Code: Select all
#!/usr/bin/perl
use Email::MIME::Creator;
use Email::Send;

$b_email   = 'somebody@example.com';
$youremail = 'service@theloo.co.uk';

my $email = Email::MIME->create(
    header => [
        From => $b_email,
        To   => $youremail,
        Subject => 'New Online Order',
    ],
    attributes => {
        content_type => "text/plain",
        charset      => "UTF-8",
    },
    body => <<"END_MESSAGE" );
A new order has been received, summary below.

The body should be just one big string.
etc...
END_MESSAGE

Email::Send->new({mailer => 'Sendmail'})->send($email);


Incorporating multi parts (check the website above) is probably the way to go, because using the basic script, in a trial like below doesn't appear to work:
Code: Select all
if ( ( $payment_method eq "Credit Card" ) || ( $payment_method eq "PayPal" ) ) {
            body => <<"END_MESSAGE" );
A new order has been received, summary below. £="&#163;" you order.
 body  should be just one big string.
   Your order will be despatched with delivery confirmation. \n
      "Payment for your order may be made through Check or Money Order, in UK Sterling ( ) or Euros only.";
          print "<br />";
          print
      "Please make checks payable to:<br /><em>ANYONE</em>";

* Orders will be posted upon receipt of payment. \n
* We shall further confirm dispatch by post of your purchase, subject to bank clearing. \n
\n
Please contact us at $youremail if you have any questions or concerns. \n
\n
END_MESSAGE
}


Help by way of collaboration is welcome, if you have experience in this area of multipart message and Mime, plus nopcart.
I'm pretty sure such a script wold be useful to others.
JOhn
chueewowee
WebMaster
 
Posts: 64
Joined: Mon Apr 16, 2007 6:57 am
Location: london, UK

Re: Script collaboration? - perl checkout/Mime::Creator

Postby Koibito » Sun Jan 13, 2008 3:02 am

I have struggled with this issue too. We have customers in Scandinavia, Brazil and Spanish-speaking countries, so we have to deal with the non-ascii chracters in their names. The data in the CSV file are okay, but it is the e-mail that gives us problems. I haven't found a solution yet. There must be an easy way to solve this. Maybe could use "use UTF-8" [http://perldoc.perl.org/utf8.html] somewhere in the script? I tried this once, and it broke the entire script :) Please let us know what you find.
John
Koibito
Site Admin / Guru
 
Posts: 918
Joined: Sun May 28, 2006 1:59 am
Location: New Jersey, USA

Re: Script collaboration

Postby chueewowee » Sun Jan 13, 2008 9:59 am

Hi Koibito,

It won't work with just declaration in the perl checkout, so I understand, and found by trial. The explanation is:

Because the native character set of email is 7-bit ASCII. If you want to use anything else, like British £ signs, you need to use MIME


A suitable perl Mme module? The tool for the job is Mime::Creator

I have used a basic email script, as given above, but to incorporate the conditional statements is the next step. From my initial research and trials, I have ruled out some methods, but need to get further with it. I'll post my recent progress very soon, and maybe someone will pick it up and spot the solution.

It would be satisfying to crack this one. I feel confident in the general direction outlined above, because I tested it with UTF8 encodings in a test mail - the basic email form given above.
I next found that the conditionals (if Method = ) cant go inside the basic form.
I next proceeded to write them as variables in conditional statements, and put the variable in the email body (Mime::Creator handles the string variable to print it in the body). That's where I'm stuck. I'll drag out the code i used for that. My knowledge of perl is limited, but I fancy you may be able to make valuable suggestions here, Koibito


Regards,
John
chueewowee
WebMaster
 
Posts: 64
Joined: Mon Apr 16, 2007 6:57 am
Location: london, UK

Re: Script collaboration - here's my progress

Postby chueewowee » Sun Jan 13, 2008 10:55 am

Hi,

here's my progress with the script in order to show what I'm doing in attempting to define the variable $message which is to go into the email body, i.e. defined by conditionals such as

if ( ( $payment_method eq "Credit Card" )

which are variables in the Kamya2 perl checkout to give payment methods using just the one checkout script.

Code: Select all
#!/usr/bin/perl
use Email::MIME::Creator;
use Email::Send;

$b_email   = 'shopper@fastmail.co.uk';
$youremail = 'admin@yahoo.co.uk';

  # Create the main body

if ( $payment_method eq "Credit Card" ) {
    $message =
'A new order has been received, summary below. should be just one big string.';
}

# Now create the email.
my $email = Email::MIME->create(
    header => [
        From    => $b_email,
        To      => $youremail,
        Subject => 'New Online Order',
    ],
    attributes => {
        content_type => "text/plain",
        charset      => "UTF-8",
    },
    body => <<"END_MESSAGE" ); "$message",
END_MESSAGE

  # Now we try to send it!
  Email::Send->new( { mailer => 'Sendmail' } )->send($email);

# Now Print to Screen
if ( ( $payment_method eq "Credit Card" ) || ( $payment_method eq "PayPal" ) ) {
    print "You will shortly receive a confirmation e-mail for your order.";
}

exit;


It's not the solution, but you can see what I'm trying to attempt, and I think it's not far off.
John
chueewowee
WebMaster
 
Posts: 64
Joined: Mon Apr 16, 2007 6:57 am
Location: london, UK

Re: Script collaboration? - perl checkout/Mime::Creator

Postby Koibito » Tue Jan 15, 2008 3:19 am

I am testing the following mail header. This seems to work for me:

Code: Select all
   open (MAIL,"|$mailprogram");
   print MAIL "To: $youremail\n";
   print MAIL "From: $b_email\n";
   print MAIL "Subject: New Online Order\n";
   print MAIL "MIME-Version: 1.0\n";
   print MAIL "Content-Type: text/plain; charset=ISO-8859-1\n";
   print MAIL "\n\n";
   print MAIL "A new order has been received.  A summary of this order appears below.\n";


This would work for the pound sign, because the pound sign is part of Latin-1 (ISO 8859-1), but not for the euro sign. If you have to deal with the euro sign, you could use the Latin-9 (ISO 8859-15) character set.

http://www.cs.tut.fi/~jkorpela/latin9.html
John
Koibito
Site Admin / Guru
 
Posts: 918
Joined: Sun May 28, 2006 1:59 am
Location: New Jersey, USA

Re: Script collaboration? - perl checkout/Mime::Creator

Postby chueewowee » Wed Jan 16, 2008 3:12 pm

10 minutes, later.

Thanks.

That solves the problem.
Excellent.
(WHen I think how long I spent on that!)
I'm rather delighted.

John
chueewowee
WebMaster
 
Posts: 64
Joined: Mon Apr 16, 2007 6:57 am
Location: london, UK


Return to Help: Perl/PHP/ASP Checkout

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron