• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

PHP email string problem

xoggoth

More fingers than teeth
Joined
Jul 8, 2005
Messages
17,133
Likes received
4,950
Thanks received
1,184
Location
xoggoth towers
Got shopping cart product lines set up to show number, description, price each etc in email sent to customer:

$description .= "$num[$i]"." ".$descs[$i]." ".$fprice[$i]." each, total = ".$fcost[$i]." \r\n";

This works fine when I email to customer directly but when I send exactly the same strings to Worldpay callback (with \r\n replaced by html entity
as they require but I don't think that's relevant) the lines are truncated at the first space. eg 3 Bird Posters etc is just 3 in the email. Any brill suggestions why? Ta.
 
Last edited: 13:42
Code:
$description .= "$num[$i]"." ".$descs[$i]." ".$fprice[$i]." each, total = ".$fcost[$i]." \r\n";

Isn't there an extra double quote?
Shouldn't that be:
Code:
$description .= "$num[$i]." ".$descs[$i]." ".$fprice[$i]." each, total = ".$fcost[$i]." \r\n";
 
I'm no expert in PHP but haven't you got double quotes around the first variable?

Shouldn't it be:

PHP:
$description .= $num[$i]." ".$descs[$i]." ".$fprice[$i]." each, total = ".$fcost[$i]." \r\n";
 
I'm no expert in PHP but haven't you got double quotes around the first variable?

Shouldn't it be:

PHP:
$description .= $num[$i]." ".$descs[$i]." ".$fprice[$i]." each, total = ".$fcost[$i]." \r\n";

Actually yes, this is better.

Haven't done php for ages.
 
Ta for comments but that ain't it. I deliberately put the 1st item in quotes to fix the same problem with my own email code and it did, just not working with the Worldpay callback email. Really don't need the . as just put vars in the string but that has the same problem, this also stops at first space and just shows 3

$description .= "$num[$i] $descs[$i] $fprice[$i] each, total = $fcost[$i] \r\n";

If I put:

$description .= "$num[$i]xxx$descs[$I]yyy$fprice[$i] each, total = $fcost[$i] \r\n";

I get xxx1yyyBird, it stops at the next space instead.
 
I'm no expert in PHP but haven't you got double quotes around the first variable?

Shouldn't it be:

PHP:
$description .= $num[$i]." ".$descs[$i]." ".$fprice[$i]." each, total = ".$fcost[$i]." \r\n";

PHP interpolates variable values for references in double-quoted strings: PHP: Strings - Manual

However this means it's unnecessary to do the concatenations. The following should work, and is easier to read:

PHP:
$description .= "$num[$i] $descs[$i] $fprice[$i] each, total = $fcost[$i] \r\n";

Not sure if this will help solve xog's problem though :ohwell
 
Ta, but tried that as said in previous. Only way I can get it through WP callback is with all spaces replaced by #, newlines by ## and change 'em all back when it reaches my code. Messy.
 
Ta for comments but that ain't it. I deliberately put the 1st item in quotes to fix the same problem with my own email code and it did, just not working with the Worldpay callback email. Really don't need the . as just put vars in the string but that has the same problem, this also stops at first space and just shows 3

$description .= "$num[$i] $descs[$i] $fprice[$i] each, total = $fcost[$i] \r\n";

If I put:

$description .= "$num[$i]xxx$descs[$I]yyy$fprice[$i] each, total = $fcost[$i] \r\n";

I get xxx1yyyBird, it stops at the next space instead.

Is there anything in the WorldPay docs about escaping spaces? If it's being sent as part of a URL you'll need to use URL encoding, e.g. add

PHP:
$description = urlencode($description);

after you've built the string to get the value to use. Dunno if that's right though; check their documentation for anything along those lines.

As it happens I spent May to September this year contracting in the same building as WorldPay on Cambridge Science Park; if I was still there I could just stop people in reception and ask them until I found somebody who knew. But I'm not there any more, so I can't. Ho hum :ohwell
 
Is it submitted as a URL? Do you need to encode the spaces as + signs?
 
From: http://www.worldpay.com/support/kb/bg/pdf/rhtml.pdf

URL Order Details String

You do not have to use an HTML form to create and submit order details, or to integrate - you
can also submit order details in a URL string. For example, you can integrate with this single
URL string:

https:// secure-test.worldpay.com/wcc/purchase?instId=123456&cartId=WorldPay+Test&amount=40.00&currency=GBP&desc=WorldPay+Test&testMode=100

As with form-based submissions, the URL order details string must contain the four
mandatory parameters, as shown in the example.

Is this the mechanism you're using? Looks like you need + for space as doodab suggested. (I always thought URLEncode stuck in %20?)

(Edit: I added the space after the // to stop it from being turned into a link...)
 
Last edited: 18:22

Advertisers

Back
Top