/    Sign up×
Community /Pin to ProfileBookmark

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=”[email protected]“><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!

to post a comment

16 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 10.2014 — 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).
Copy linkTweet thisAlerts:
@Gray1989Jan 10.2014 — 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:

[code=php]<?php
function cURLSubmit($formpage,$formarray,$postget) {
$submstr = "";
foreach ($formarray as $formkey => $formvalue) {
if($submstr != "") $submstr .= "&";
$submstr .= "$formkey=" . urlencode($formvalue);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
switch ($postget) {
case "post":
curl_setopt($ch, CURLOPT_URL, $formpage);

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $submstr);
break;
case "get":
curl_setopt($ch, CURLOPT_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"] = "[email protected]";
cURLSubmit("http://www.hostmonster.com/monstermail",$formdata,"post"); }
?>[/code]


If you need any help with it, let me know!
Copy linkTweet thisAlerts:
@Gray1989Jan 10.2014 — 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 ?
Copy linkTweet thisAlerts:
@Gray1989Jan 10.2014 — 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.
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 10.2014 — 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.
Copy linkTweet thisAlerts:
@Gray1989Jan 10.2014 — 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 [I]autofills the email address[/I] (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.

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?[/QUOTE]

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):

[code=php]$formdata["sendtoemail"] = "[email protected]";[/code]
Copy linkTweet thisAlerts:
@Gray1989Jan 10.2014 — 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="[email protected]"><br>
<input type="submit" value="Send Email"> </form>[/CODE]


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>[/CODE]
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 11.2014 — 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
Copy linkTweet thisAlerts:
@NogDogJan 11.2014 — web crawlers will not see the PHP source code, only any text output by that file should they call that URL directly.
Copy linkTweet thisAlerts:
@Gray1989Jan 11.2014 — Congrats on what you've accomplished so far, PeterPan. Good luck!
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 13.2014 — 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.
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 13.2014 — 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.
Copy linkTweet thisAlerts:
@Gray1989Jan 13.2014 — 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.[/QUOTE]

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):

[code=php]<?php
function cURLSubmit($formpage,$formarray,$postget) {
$submstr = "";
foreach ($formarray as $formkey => $formvalue) {
if($submstr != "") $submstr .= "&";
$submstr .= "$formkey=" . urlencode($formvalue);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
switch ($postget) {
case "post":
curl_setopt($ch, CURLOPT_URL, $formpage);

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $submstr);
break;
case "get":
curl_setopt($ch, CURLOPT_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"] = "[email protected]";
cURLSubmit("http://www.hostmonster.com/monstermail",$formdata,"post"); }
?>[/code]


By the way, use [ CODE ] some code here [ /CODE ] or [ PHP ] some code here [ /PHP ] (without the spaces) to get the code boxes
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 13.2014 — 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. :-(
Copy linkTweet thisAlerts:
@Gray1989Jan 14.2014 — It's possible that you have errors turned off by default and that cURL isn't working at all. No errors isn't good for debugging. Unfortunately I'm really busy right now, I'll help more when I can.
Copy linkTweet thisAlerts:
@PeterPan_321authorJun 02.2014 — It's possible that you have errors turned off by default and that cURL isn't working at all. No errors isn't good for debugging. Unfortunately I'm really busy right now, I'll help more when I can.[/QUOTE]


I know the thread is very old, but I just thought I'd chime in and mention that I finall did come to learn and understand a bit more about how to write my own PHP driven forms. I've been criticized a lot for my coding methods, which are an admitted hodge podge of old and new coding. But the bottom line is the forms work and the pages seem to display well on a variety of browsers. If you're interested, the original form I needed requires you to go www.elfintechnologies.com, and click the contact item on the menu.

I've done a few forms like this now, where the whole page is a php file, instead of having an HTML file that calls a separate php file. I didn't use CURL, and didn't use the php script that my hosting company provided me. I guess once I learned that I could send email directly from my PHP page (something obvious I guess which I didn't realize), everything came together. Anyway, the help was appreciated.
×

Success!

Help @PeterPan_321 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...