1 Reply Latest reply on Jun 23, 2009 6:13 PM by kid electric

    Problems passing vars to form mailer PHP

    kid electric

      Okay, so, I've searched and searched the web as well as the forums here, but can't find a simple, good, "all-in-one" example of how to perfectly send email via Flex.  What i've done is created a form (with textinputs for firstname, lastname, contact email and/or phone number, subject, and a textarea for the message, plus a "submit" button)

       

      I created an HTTPService like so:

       

       

       <mx:HTTPService id="hsContactService" contentType="application/xml" url="contact.php" useProxy="false" fault="httpService_fault(event)" result="hsContact_result(event)" method="GET">
      <mx:request xmlns="">
      <email>{sEmail}</email><subject>{tiSubject.text}</subject><phone>{tiPhone.text}</phone>
      <from>{tiEmail.text}</from><message>{taMessage.text}</message><name>{tiFirstname.text + " " + tiLastname.text}</name>
      </mx:request>
      </mx:HTTPService>
      
      

      As you can see, I placed an mx:request object inside the httpService, containing all of the variables I want to send for the email. (some are static and some come from from input boxes, but none seem to be working -- and I made them all Bindable)

       

      on button click event, I trigger a call to hsContactService.send()

       

      which makes a service send to contact.php, which looks like this:

       

      <?php 
      $to = example@hvlcomputers.com
      $subject = "HVLComputers.com: "+ $_$REQUEST['subject']; 
      if ($email == "") $email = "noreply@hvlcomputers.com"; 
      else $email = $_REQUEST['from'];
      $message = $_REQUEST['message'] + "Contact: " + $_REQUEST['phone']; 
      $headers = "From: "+ $_REQUEST['name']; 
      $sent = mail($to, $subject, $message, $headers); 
      if($sent) 
      {print "Your email was sent successfully"; }
      else 
      {print "We encountered an error sending your mail"; }
      ?> 
      
      


      Now, I know the HTTPService is successfully finding and triggering contact.php, because it does, in fact, send an email every time the Submit button is clicked.

       

      Here is the problem: it is not sending any of the request/POST vars as specified (which renders it useless); all I see in the email are:

      Subject: 0

      Message:

      0

       

      0

       

       

      I'm at a loss as to why the request vars seem to be being ignored.

        • 1. Re: Problems passing vars to form mailer PHP
          kid electric Level 1

          Fixed it!  I think the main problem was that I was combining strings the wrong way in PHP... I was using "+" instead of "." to combine strings.  I haven't used PHP in a while... maybe that was turning the strings into ints?

           

          Anyway, I also had to remove the contentType ="application/xml" property of the HTTPService... that had never made sense to me anyway, but I had seen somewhere that you had to do that to send the posted vars as an XML request object (which is not the case)