OzonesDeck - 09 Dec. 2007 - 23:59:
Need a "web design" app
I am not familiar with programing in PERL, but I need a simple little app that I'm sure someone has.... I need something that will take Form Field Values from an HTML page, and turn them into E-Mail, sending through the server's STMP... Also setting the recipients, and senders addresses, the Mail title, CC, and BCC, and the Body. Anybody got, or know of something suitable?
10 Dec. 2007 - 11:00
grigri
I do all web development in PHP. Most of my form systems are integrated one way or another with a framework, and generally use a 3rd-party mail component like PhpMailer() or CakePHP's EmailComponent - which do handle smtp, although I generally just use mail/sendmail.
Still, if you'd like this kind of help, I'm happy to send you some code / give you some pointers. But perl is really not my thing...
10 Dec. 2007 - 12:14
OzonesDeck
Yeah Grigri, I definately need some help here. My boss indicates that PERL is a functional Server-Side script for their hosting service. I will ask about PHP. Do they usualy work on the same servers?
What I have going is this: my HTA program conjoins reports from several terminals (laptops in the security patrol vehicles) which is melded into an HTML document that I need to send as an EMail to the account holder. The script can generate all the required data, including the recipient's address. I was figuring on just pasting the output into form fields, and using the form.submit() function to pull it all together.I could just dump it out to a text file or something if I need to. I suppose I could also intergrate into Outlook if I knew how, but I'm trying to limit dependance on 3rd party apps.
If you have a PHP solution / idea, I'd GREATLY appreciate the help.
Thanks!
-Ozone
10 Dec. 2007 - 12:38
grigri
If all your fields are auto-generated and you don't have to worry about validation, then it makes things a LOT easier. Ditto if you don't need MIME mail (HTML, Attachments, ...). Plain text is soooo easy.
Basically, if you have a form, each field's value will be transmitted as an associative array (name => value) to PHP. This snippet will grab everything and put it into a plain text email and send it:
$subject = "This is your captain speaking";
$to = "User <user at example dot com>";
$from = "Your Captain <captain at example dot com>";
$body = "";
foreach ($_POST as $key => $value) {
$lines = explode("n", $value);
if (count($lines) > 1 || strlen($lines[0]) > 40) {
// Long line
$body .= $key . "n" . str_repeat('-', strlen($key)) . "n" . implode("n", $lines);
}
else {
// Short line
$body .= $key . " : " . $value;
}
// More linebreaks
$body .= "nn";
}
$headers = "From: $from";
mail($to, $subject, $body, $headers);
Of course, you can get much more complicated than that, should you want/need to.
11 Dec. 2007 - 03:06
OzonesDeck
Grigri, Okay, I think I get the gist here.... a few questions remain:
1> How do I associate this script with a forms output? How do I call it as a result of ".Submit()"?
2> Do I just "cut and paste" this code and save as SUBMIT.PHP and upload to server? (I figure there is more needed)
a> Is there a headder / footer needed for PHP
b> I presume we need to set up something so that $subject, ect... arnen't Staticaly set, but set from the originating form
The only thing that concerns me, is that I am attempting to send the body of the message as an HTML document. I have already done all spell-checking, and e-mail validation before it hits this point.
Thanks Grigri - you are savin' my sanity!
-Ozone
11 Dec. 2007 - 13:12
grigri
Associating the form is simple. your form declaration should look like this:
<form method="post" action="http://yourserver/submit.php">
<!-- normal form fields here -->
<input type="submit" value="Click here to send" />
</form>
The action attribute is where the information is sent, and that happens whenever the form is submitted, either through the user clicking the button, through script, or whatever.
Example of simple data:
Form field: <input type="text" name="name" />
PHP: $_POST['name']
While you're debugging, just put print_r($_POST) in your php file.
Is there more needed? No, not really - although some output would be nice. PHP code has to be wrapped in <?php ... ?> tags, anything outside this is sent back to the browser (typically html). You can call echo() or print() from php to send back stuff too.
footers are not part of the HTTP specification; no such thing. For headers, you can send them if you need to, but it defaults to response 200 and content-type text/html. If you need to change that, do this from php:
<?php
header("Content-type: application/hta");
?>
Just make sure you send the headers befoer you send any output - unless you're using output buffering. If you don't you'll get a warning/error, and the header won't work.
Sending the email message as HTML isn't that hard either -
see the example on php.net
17 Dec. 2007 - 08:58
OzonesDeck
Grigri,
Thanks for your time on this, and I get the gist of it. Could I beg of you to generate the PHP app for this, and a simple HTML form to m ake it go, so that I can crawl inside and see it in action?
-Ozone
18 Dec. 2007 - 20:29
beaker
08 Jan. 2008 - 12:18
OzonesDeck
Grigri,
Okay, I tried to combine all the info above. Heres what I have come up with:
<?php
//---First Attempt At PHP Mail Processing Center
//---Special Thanks to Grigri at
http://www.virtualplastic.net
$subject = $_POST['Subject'];//"This is your captain speaking";
$to = $_POST['SendTo'];//"User
";
$from = $_POST['SendFrom'];//"Your Captain <captain at example dot com>";
$body = $_POST['MessageBody'];//"";
foreach ($_POST as $key => $value) {
$lines = explode("n", $value);
if (count($lines) > 1 || strlen($lines[0]) > 40) {
// Long line
$body .= $key . "n" . str_repeat('-', strlen($key)) . "n" . implode("n", $lines);
}
else {
// Short line
$body .= $key . " : " . $value;
}
// More linebreaks
$body .= "nn";
}
$headers = "From: $from";
mail($to, $subject, $body, $headers);
?>
But I am worried that I am sending about 3000 Characters in formated HTML as the Body of the email..... I don't think this will quite handle it... Can you check this for me?
08 Jan. 2008 - 22:46
craeonics
I've sent much, much bigger emails than mere 3000 characters through mail(), don't worry about that.
Three things to take note of:
1) If you want to send HTML-email, you need additional headers. As grigri said, check the examples in the
documentation for mail().
2) All those n's in grigri's code are actually \n's. The forum ate the backslashes.
3) Using user input as the recipient address is great for spammers. Better hardwire that to-address and not grab it from the form.
16 Feb. 2008 - 10:25
OzonesDeck
Okay, I'm in deep trouble now, and need some help fast! Aperently my boss's Web server is pretty much useless for any server-side scripting. I have 2 weeks to get a solution. What I need to do is: send an EMail to an address generated by my script. The body of the email is an HTML page, probably containing linebreaks. The "return" email address needs to match up to my company. I am absoloutley fine with attatching this to Outlook, or OE. I think my bos would prefer this. I need something that is effectively "Client Side" to handle this function. Server-side solutions wont work with his server. Client computers are XP + Vista.
PLEASE HELP!!!
Additionaly, if someone knows a way that I can set up hosting on a web server that can handle this type of job, let me know. If it takes hosting webspace just for a PHP process, I'll do what it takes.
18 Feb. 2008 - 01:57
DiosDePyro
You may be able to play with this program and get it to send mails for you, it's a commandline utility for sending mail, but you can get it to run in c++ with some work
You can get it
here
23 Feb. 2008 - 06:52
OzonesDeck
Dios,
THANK YOU!!!! I think you saved my bacon. This runs great from command line. I'm tying it in through JavaScript, any tip's from anyone on running a command line command with multiple switches? I seem to remrmber having dificulty doing this with RunProtocolHandler, but honestly don't remember. I would also like to avoid having the "System" box with black background flash up. But as long as I can make it go, I dont care. Thank you again Dios! =)
-Ozone
24 Feb. 2008 - 05:21
DiosDePyro
No problem! All it took was a little Googling ; ]
Can you set the entire command (with switches) as a string, and execute it at once?
02 Mar. 2008 - 06:37
OzonesDeck
Dios,
Yep, here is the command set I'm using from Javascript:
var QU=String.fromCharCode(34)
var RunBox="sendEmail/sendEmail -f "+QU+"Security Company <securitycompany at server dot net>"+QU+" -t "+Primary.EMailSendto+" -u "+Primary.EMailSubject+" -s SMTP.comcast.net:25 -o message-file="+Primary.Storage+"EMail.html"
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run(RunBox);
I have the outgoing email complied and saved prior to execution. I will likely have to make something a bit more advanced so that I can send several "at once" using a batch file, but I have the core of how to do it now, thanks to you!
-Ozone
Please log-in to post.
You need to be logged in to post. To log-in, or to register an account go -
there.
Options