• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • 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

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP email string problem

    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 by xoggoth; 15 November 2013, 13:45.
    bloggoth

    If everything isn't black and white, I say, 'Why the hell not?'
    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

    #2
    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";
    <Insert idea here> will never be adopted because the politicians are in the pockets of the banks!

    Comment


      #3
      I'm no expert in PHP but haven't you got double quotes around the first variable?

      Shouldn't it be:

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

      Comment


        #4
        Originally posted by Bunk View Post
        I'm no expert in PHP but haven't you got double quotes around the first variable?

        Shouldn't it be:

        PHP Code:
        $description .= $num[$i]." ".$descs[$i]." ".$fprice[$i]." each, total = ".$fcost[$i]." \r\n"
        Actually yes, this is better.

        Haven't done php for ages.
        <Insert idea here> will never be adopted because the politicians are in the pockets of the banks!

        Comment


          #5
          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.
          bloggoth

          If everything isn't black and white, I say, 'Why the hell not?'
          John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

          Comment


            #6
            Originally posted by Bunk View Post
            I'm no expert in PHP but haven't you got double quotes around the first variable?

            Shouldn't it be:

            PHP Code:
            $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 Code:
            $description .= "$num[$i] $descs[$i] $fprice[$i] each, total = $fcost[$i] \r\n"
            Not sure if this will help solve xog's problem though

            Comment


              #7
              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.
              bloggoth

              If everything isn't black and white, I say, 'Why the hell not?'
              John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

              Comment


                #8
                Originally posted by xoggoth View Post
                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 Code:
                $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

                Comment


                  #9
                  Is it submitted as a URL? Do you need to encode the spaces as + signs?
                  While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

                  Comment


                    #10
                    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=10 0

                    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 by mudskipper; 15 November 2013, 18:25.

                    Comment

                    Working...
                    X