www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: problem less than ideal form mail

  1. #1
    Join Date
    Jun 2004
    Location
    Tampa, Florida
    Posts
    77

    Unhappy problem less than ideal form mail

    My hosting company (Hostmonster.com) provides a service called "MonsterMail". It lets me set up a form. their example looks pretty typical...

    <form action="http://www.hostmonster.com/monstermail" enctype="multipart/form-data" method="POST">
    Name: <input type="text" name="Name"><br>
    Email: <input type="text" name="mailfrom"><br>
    Street Address: <input type="text" name="StreetAddress"><br>
    City: <input type="text" name="City"><br>
    Zip: <input type="text" name="Zip"><br>
    Phone: <input type="text" name="Phone"><br>
    <input type="hidden" name="sendtoemail" value="myemail@mydomain.com"><br>
    <input type="submit" value="Send Email"> </form>

    So one thing I added was a text area, like this, right after the Phone: line.

    <div align="center"> ---- Message ----<br>
    <textarea name="Message" wrap="physical" cols="40" rows="10" ></textarea>
    </div>

    This form, once submitted (apparently to "http://www.hostmonster.com/monstermail" ), formats and re-transmits all the info to me, in an email. naturally in my actual case, i use some javascript to hide me email address.

    well it works, but the problem is that any and all line breaks the user enters in the <textarea> get stripped. If the user write 10 paragraphs, they are all going to run together without a clue as to where he/she intended the line breaks to go. Now I've checked and re-checked. A "textarea", with the "wrap" attribute set to "physical", is supposed to preserve all line breaks, and send them to the server exactly as acquired. Unfortunately thats not the way it is when the email arrives.

    I've talked to hostmonster. All they gave me was BS. After trying to pull my leg about line breaks possibly causing a security proble, they finally conceded that the script that controls this, whatever it may be, is so old nobody has a clue about it, and then more BS that if they fixed it they would likely break a lot of hosted web sites. Can you just smell smell the $#!+?

    So anyway, my first question is whether this problem is typical of all form mail. Second, is there anything in the form <action> tag that i could change to force the better behavior, and third, if there's really nothing I can do, what other alternatives do I have for form mail that i can use instead, if possible with minor modifications, and (the tough one) free. Obviously I need some hind of server, so if the one my hosting company provides is crap, I'm going to need something I can put in my own "cgi-bin" director that i can use, along with some brain dead instructions for people like me, not very well versed in server side scripting.

    Thanks in advance!
    Randy (PeterPan)
    * * *
    * *
    ... Second Star to the Right, and Straight on Till Morning!
    * * *

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    There must be hundreds of PHP mail scripts out there you could use (I'm assuming your hosting account includes PHP?). Unfortunately I cannot recommend any specific ones, since I'd just throw one together when I need it (possibly using the PHPMailer class if it's going to include attachments and/or sending through a separate SMTP email account).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2012
    Posts
    202
    Here's a PHP script you can use for your web-based email form so that you don't have to worry about others getting and using your email for spam purposes:

    PHP Code:
    <?php
    function cURLSubmit($formpage,$formarray,$postget) {
    $submstr "";
     foreach (
    $formarray as $formkey => $formvalue) {
      if(
    $submstr != ""$submstr .= "&";
     
    $submstr .= "$formkey=" urlencode($formvalue);
     }
    $ch curl_init();
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
     switch (
    $postget) {
      case 
    "post":
       
    curl_setopt($chCURLOPT_URL$formpage);  
       
    curl_setopt($chCURLOPT_HEADER0);
       
    curl_setopt($chCURLOPT_POST1);
       
    curl_setopt($chCURLOPT_POSTFIELDS$submstr);
       break;
      case 
    "get":
       
    curl_setopt($chCURLOPT_URL$formpage '?' $submstr);
       break;
     }
    curl_exec($ch);
    curl_close($ch);
    }

    if(isset(
    $_POST["Name"]) && isset($_POST["mailfrom"]) && isset($_POST["StreetAddress"]) && isset($_POST["City"]) && isset($_POST["Zip"]) && isset($_POST["Phone"]) && isset($_POST["Message"])) {
    $formdata = array();
    $formdata["Name"] = $_POST["Name"];
    $formdata["mailfrom"] = $_POST["mailfrom"];
    $formdata["StreetAddress"] = $_POST["StreetAddress"];
    $formdata["City"] = $_POST["City"];
    $formdata["Zip"] = $_POST["Zip"];
    $formdata["Phone"] = $_POST["Phone"];
    $formdata["Message"] = $_POST["Message"];
    $formdata["sendtoemail"] = "myemail@mydomain.com";
    cURLSubmit("http://www.hostmonster.com/monstermail",$formdata,"post"); }
    ?>
    If you need any help with it, let me know!
    Last edited by Gray1989; 01-10-2014 at 12:45 PM.

  4. #4
    Join Date
    Mar 2012
    Posts
    202
    If you get this to work, it might be possible to include a fix directly in this PHP code to take care of that annoying line-break problem

  5. #5
    Join Date
    Mar 2012
    Posts
    202
    I made a couple of modifications just now to the code (sorry I actually haven't had a chance to thoroughly test the code). Just a heads up to make sure that if you're having a problem it might be because of that.

  6. #6
    Join Date
    Jun 2004
    Location
    Tampa, Florida
    Posts
    77
    OK sorry... I had to get some other chores done so I've been away for most of the afternoon. Well for this. First things first, and please remember, this will be my very first DIRECT use of PHP (meaning installing something rather than using some "magic", so I'm going to ask some dumb questions...

    1) this is PHP code... so should I put it in a file called something "myMailHandler.PHP"?
    2) I suppose I should put it in my "cgi-bin" folder?
    3) What do I need to do to my http mail form page to make it call this script?
    4) I notice the script calls cURLSubmit("http://www.hostmonster.com/monstermail",$formdata,"post"); Well my form already calls this server. So how will installing this "go between" script make it behave any differently?

    So let me know, and I'll give it a try. Thanks again.
    Randy (PeterPan)
    * * *
    * *
    ... Second Star to the Right, and Straight on Till Morning!
    * * *

  7. #7
    Join Date
    Mar 2012
    Posts
    202
    This is a PHP script designed to redirect web form requests using the webserver itself as a sort of proxy (using cURL). Quite simply put, it's a dummy page that will redirect the form request to the actual location from the server (as opposed to the client). This way, the server acts as a man-in-the-middle which autofills the email address (absolute 0.00% spambot risk). Server-side code such as PHP gets rendered by the server and sends the resulting web page to the browser (all the client gets is HTML/CSS/JS), so we can take advantage of this to safely store the email directly in PHP's source code.

    Quote Originally Posted by PeterPan_321 View Post
    1) this is PHP code... so should I put it in a file called something "myMailHandler.PHP"?
    2) I suppose I should put it in my "cgi-bin" folder?
    3) What do I need to do to my http mail form page to make it call this script?
    4) I notice the script calls cURLSubmit("http://www.hostmonster.com/monstermail",$formdata,"post"); Well my form already calls this server. So how will installing this "go between" script make it behave any differently?
    1) Yes! Exactly.
    2) Put it where you would normally put .html files; Wherever you want. It needs to be in a location that the public has permissions to access. If your PHP implementation is set up correctly, the source code of the PHP code shouldn't be sent to the browser when you try to access it. You may receive one or more errors but if you do, don't let it discourage you.
    3) Change http://www.hostmonster.com/monstermail to the URL of the .php file in the form on your page (if in same directory, simply replace with "myMailHandler.PHP", as you put it)
    4) Since the PHP script acts as the middle-man, it essentially has ultimate control of the communications. This is just designed to prevent spam attacks, but PHP is much more useful in these situations as-well. If your package comes with an SMTP server, then we should be able to send the email directly using an existing API inside of PHP. That's just one example.

    Navigate to the public URL of the .php file on your server. Check for errors, and make sure that the original source code isn't visible while you're on the page.

    If no errors:

    In order to get the PHP file working, you must first modify this line (the 2nd last, to reflect the actual email):

    PHP Code:
    $formdata["sendtoemail"] = "myemail@mydomain.com"
    Last edited by Gray1989; 01-10-2014 at 05:42 PM.

  8. #8
    Join Date
    Mar 2012
    Posts
    202
    This is your original code:

    Code:
    <form action="http://www.hostmonster.com/monstermail" enctype="multipart/form-data" method="POST">
    Name: <input type="text" name="Name"><br>
    Email: <input type="text" name="mailfrom"><br> 
    Street Address: <input type="text" name="StreetAddress"><br> 
    City: <input type="text" name="City"><br> 
    Zip: <input type="text" name="Zip"><br> 
    Phone: <input type="text" name="Phone"><br> 
    <input type="hidden" name="sendtoemail" value="myemail@mydomain.com"><br>
    <input type="submit" value="Send Email"> </form>
    This is what it should look like (omitting email field entirely and pointing the form's action field to your .php file:

    Code:
    <form action="http://www.mydomain.com/myMailHandler.PHP" enctype="multipart/form-data" method="POST">
    Name: <input type="text" name="Name"><br>
    Email: <input type="text" name="mailfrom"><br> 
    Street Address: <input type="text" name="StreetAddress"><br> 
    City: <input type="text" name="City"><br> 
    Zip: <input type="text" name="Zip"><br> 
    Phone: <input type="text" name="Phone"><br> 
    <input type="submit" value="Send Email"> </form>

  9. #9
    Join Date
    Jun 2004
    Location
    Tampa, Florida
    Posts
    77
    Hey Gray! Only think I'm not sure of, is since the email is in the PHP script, what prevents a SPAM-BOT from examining that file?

    But anyway, thanks so much for all this work. I Hope I can be equally helpful to you someday. In fact maybe when I'm done, you'll see something on my website you'd be interested in. I'll try this over the weekend if I have time, though I may wait till Monday because I need a break (and a beer!), as its been a long week. Funny how becoming unemployed can inspire you to work harder than ever! (LOL!). This past week, with a lot of online help and tutorials, I built a nice CSS based template I like for my website, got SSI to work (so I can re-use the template), got a form mail (at least the original one) to work, as well as an alternate HTML email solution when the visitor has scripting disabled. I also re-learned how to use the HTTP_REFERER variable in my .HTACCESS file to block both hot links attempts to images, and undesired access to private pages. I also learned a lot more than I ever knew about CSS, (some good , some bad, and some still VERY ugly IMHO). So all in all, I'm off to a good start. In fact I got more done in the past week than I did with wordpress in the same span of time span last. Take a look! (This will eventually become my official obligatory "under construction", and "why I'm here" page ;-) I'll let you know how the PHP script works.

    http://elfintechnologies.com/testpage005.html
    Randy (PeterPan)
    * * *
    * *
    ... Second Star to the Right, and Straight on Till Morning!
    * * *

  10. #10
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    web crawlers will not see the PHP source code, only any text output by that file should they call that URL directly.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  11. #11
    Join Date
    Mar 2012
    Posts
    202
    Congrats on what you've accomplished so far, PeterPan. Good luck!

  12. #12
    Join Date
    Jun 2004
    Location
    Tampa, Florida
    Posts
    77
    Gray1989.. Back from a badly needed break here, and working on this again. Som one thing I still think I may be confused about. I understand I need to change the "mostermail" URL in my form to point to the PHP code module we're working on. But in that PHP example, it also says "cURLSubmit("http://www.hostmonster.com/monstermail",$formdata,"post");", and it seems you suggested I change that to point to the PHP module too. This doesn't seem to make sense, because you said it was a middleman, and I don't think we'd want the PHP module to call itself, right? So wouldn't I need to know the something about my mailserver's URL to fill that function call? Remember, that "monstermail" url was probably the location of the PHP whose behavior I don't like, so I don't think you're wanting me to post back to that.

    By the way, when I post code examples, what do i need to do to set it off in its own area as you've been doing.
    Randy (PeterPan)
    * * *
    * *
    ... Second Star to the Right, and Straight on Till Morning!
    * * *

  13. #13
    Join Date
    Jun 2004
    Location
    Tampa, Florida
    Posts
    77
    Anyway, I assumed I should leave the URL to the "monstermail" in the PHP module, and use the URL to the PHP module in my formmail. The temp htmlform is at http://elfintechnologies.com/elfmail.html. Upon filling it out and clicking the button to submit, it does switch the URL in my browser to the PHP module with no error. But that just leaves me with a white screen. There's no indication that anything ran, or that any errors occurred. No mail came to my inbox, for sure. I guess all this is to be expected the first time one tries a PHP script, but this is code running in an environment where I have no obvious way to debug.
    Randy (PeterPan)
    * * *
    * *
    ... Second Star to the Right, and Straight on Till Morning!
    * * *

  14. #14
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by PeterPan_321 View Post
    Anyway, I assumed I should leave the URL to the "monstermail" in the PHP module, and use the URL to the PHP module in my formmail. The temp htmlform is at http://elfintechnologies.com/elfmail.html. Upon filling it out and clicking the button to submit, it does switch the URL in my browser to the PHP module with no error. But that just leaves me with a white screen. There's no indication that anything ran, or that any errors occurred. No mail came to my inbox, for sure. I guess all this is to be expected the first time one tries a PHP script, but this is code running in an environment where I have no obvious way to debug.
    You assumed correctly. Try changing "curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);" to "curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);" in the .php file, this will tell the script to return you the output from the page it's sending the data to. Since you've seen no errors so far, that means the .php script is actually running smoothly. Also, I've noticed this: "<input type="hidden" name="redirect" value="http://elfintechnologies.com/mailconfirm.html">" which I did not account for. Use this as the updated PHP code (make the same change as before):

    PHP Code:
    <?php
    function cURLSubmit($formpage,$formarray,$postget) {
    $submstr "";
     foreach (
    $formarray as $formkey => $formvalue) {
      if(
    $submstr != ""$submstr .= "&";
     
    $submstr .= "$formkey=" urlencode($formvalue);
     }
    $ch curl_init();
    curl_setopt($chCURLOPT_RETURNTRANSFER0);
     switch (
    $postget) {
      case 
    "post":
       
    curl_setopt($chCURLOPT_URL$formpage);  
       
    curl_setopt($chCURLOPT_HEADER0);
       
    curl_setopt($chCURLOPT_POST1);
       
    curl_setopt($chCURLOPT_POSTFIELDS$submstr);
       break;
      case 
    "get":
       
    curl_setopt($chCURLOPT_URL$formpage '?' $submstr);
       break;
     }
    curl_exec($ch);
    curl_close($ch);
    }

    if(isset(
    $_POST["Name"]) && isset($_POST["mailfrom"]) && isset($_POST["StreetAddress"]) && isset($_POST["City"]) && isset($_POST["Zip"]) && isset($_POST["Phone"]) && isset($_POST["Message"]) && isset($_POST["redirect"])) {
    $formdata = array();
    $formdata["Name"] = $_POST["Name"];
    $formdata["mailfrom"] = $_POST["mailfrom"];
    $formdata["StreetAddress"] = $_POST["StreetAddress"];
    $formdata["City"] = $_POST["City"];
    $formdata["Zip"] = $_POST["Zip"];
    $formdata["Phone"] = $_POST["Phone"];
    $formdata["Message"] = $_POST["Message"];
    $formdata["redirect"] = $_POST["redirect"];
    $formdata["sendtoemail"] = "myemail@mydomain.com";
    cURLSubmit("http://www.hostmonster.com/monstermail",$formdata,"post"); }
    ?>
    By the way, use [ CODE ] some code here [ /CODE ] or [ PHP ] some code here [ /PHP ] (without the spaces) to get the code boxes

  15. #15
    Join Date
    Jun 2004
    Location
    Tampa, Florida
    Posts
    77
    Thanks Gray. No that didn't do anything either. But I don't believe "no errors" means its running smoothly. An adage one of my fellow engineers used to say: " No News is not GOOD news... no news is NO NEWS". So I took you're updated script and turned the monstermail URL into something impossible, to try to make it generate a error (I'd think "http://nowsabjasbhere.com" ought to generate some kind of host unreachable error). The behavior didn't change and still no error log. So then I changed the last line from "cURLSubmit to cURLSub[naughty word] and tried again. Still no change in behavior nor error log.

    So now I'm back to square one. I know I have PHP active, and I did find a note in a google search somewhere that Curl did work on hostmonster, but right now I have reason to doubt the module is even executing.

    Sorry I'm so UN-knowledgable about this stuff. But maybe I need the PHP equivalent of a "hello world" before trying anything like this. Sadly, (and this is scarey) I am much more knowledgeable that at least 1/2 of the hostmonster reps I've dealt with over the past month. :-(
    Last edited by PeterPan_321; 01-13-2014 at 05:26 PM.
    Randy (PeterPan)
    * * *
    * *
    ... Second Star to the Right, and Straight on Till Morning!
    * * *

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles