Web Hosting Forums

Page 1 of 2 1 2 LastLast
Results 1 to 15 of 21

This is a discussion on Mail Script in the Hosting Talk & Chit-chat forum
Ok, still in the learning process here, so bear with me if this seems stupid... A basic mail form script was easy to setup and ...

  1. #1
    Loyal Client
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    387

    Mail Script

    Ok, still in the learning process here, so bear with me if this seems stupid...

    A basic mail form script was easy to setup and works great as long as I specify in the processor exactly what e-mail address I want the mail sent to. However, what if I want to be able to enter the recipient address into the form to specify where I want the mail sent? Obviously, I'm not going to go implementing this on my site (as that would be an easy tool for spammers), but I still want to learn how to do it. Here's what I have so far, which worked fine until I added the "To" field:

    Code:
    mail.php
    
    <form action="processmail.php" method="post">
    To: <input type="text" name="to" size="20" maxlength="20"><br />
    Your Name: <input type="text" name="name" size="20" maxlength="20"><br />
    Your Email: <input type="text" name="email" size="30" maxlength="30"><br />
    Subject: <input type="text" name="subject" size="30" maxlength="30"><br />
    Text:<textarea name="text" name="text" cols="50" rows="10"></textarea><br />
    <input type="submit" name="submit" value="Send">
    </form>
    
    processmail.php
    
    <?php
    @extract($_POST);
    $to = stripslashes($to);
    $name = stripslashes($name);
    $email = stripslashes($email);
    $text = stripslashes($text);
    mail('$to',$subject,$text,"From: $name <$email>");
    header("location:submitok.html");
    ?>
    Am I missing something blatantly obvious here? I feel like I am....

  2. #2
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,661

    Re: Mail Script

    Originally posted by Galen
    Code:
    mail.php
    
    <form action="processmail.php" method="post">
    To: <input type="text" name="to" size="20" maxlength="20"><br />
    Your Name: <input type="text" name="name" size="20" maxlength="20"><br />
    Your Email: <input type="text" name="email" size="30" maxlength="30"><br />
    Subject: <input type="text" name="subject" size="30" maxlength="30"><br />
    Text:<textarea name="text" name="text" cols="50" rows="10"></textarea><br />
    <input type="submit" name="submit" value="Send">
    </form>
    
    processmail.php
    
    <?php
    @extract($_POST);
    $to = stripslashes($to);
    $name = stripslashes($name);
    $email = stripslashes($email);
    $text = stripslashes($text);
    mail('$to',$subject,$text,"From: $name <$email>");
    header("location:submitok.html");
    ?>
    Where's this?
    Code:
    $subject = stripslashes($subject);
    Also, you might try this...
    Code:
    mail("$to",$subject,$text,"From: $name <$email>");
    Last edited by Vin DSL; 05-31-2004 at 04:53 AM.
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL 2010

  3. #3
    Loyal Client
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    387
    Where the $subject; ? Why, Vin, that's a very good question! I hadn't noticed it before because the script, does in fact work (and the subject shows up correctly). Now that you've pointed that out, I'm very curious to know WHY the subject gets posted. It doesn't look like it should...

    *slaps forehead* Thanks Vin, that made the script work. I had just replaced the e-mail address that was formatted as '[email protected]' with the $to variable and didn't think to change those apostrophes to quotes.

    Thanks again!

  4. #4
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    By default in the JPC config of php register_globals is on, so no special processing has to be done to make form variables available to PHP. So just using $subject in the mail() call is passing the form value of 'subject' to the email message.

    On the other hand (as you've already discovered, PHP only does variable substitution in double-quoted strings, so '$to' was being traeated as a literal string instead of substituting the form variable 'to.'

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  5. #5
    Loyal Client
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    387
    Hehe, which explains why it got bounced back to me with a message saying that there's no user [email protected] lol. It works now, thankfully.

    What I'm trying to do now is complete the process of making this script totally anonymous. For years I've been hearing people talk about how it's "so easy" for spammers to hide the origins of their messages and I've never understood HOW it's done. Obviously, I understand it now, though. They've probably been using cgi and later php scripts to do it.

    Anyway, my final step in this is to remove the server name from the header, by having a field for "Recieved" which would replace the line in the header that says "Received: from falcon.nocdirect.com by blah blah blah blah blah etc" So far, everything I've tried doesn't work. Maybe php's mail function can't do it? I dunno...

    Anybody know how to do what I'm trying to do?

  6. #6
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,661
    Originally posted by Galen
    Anyway, my final step in this is to remove the server name from the header, by having a field for "Recieved" which would replace the line in the header that says "Received: from falcon.nocdirect.com by blah blah blah blah blah etc" So far, everything I've tried doesn't work. Maybe php's mail function can't do it? I dunno...

    Anybody know how to do what I'm trying to do?
    This should get you in the ballpark...

    http://us3.php.net/str-replace
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL 2010

  7. #7
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,414
    One more question: What does the subroutine "stripslashes" do? I don't work in php so I don't know how good it is at cleaning (read securing) posted input data. I notice that the string $_POST is processed(parsed?) to some degree, but unless you are doing some data checking in the stripslashes sub, then you may be running a very insecure script. I hope you are not assuming that the script mail.php is limiting data input by using constraints such as 'size="20" maxlength="20"' for user input. If it runs anything like a Perl script, then you are running an insecure script. Remember, always trust users, never trust their input.

  8. #8
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    stripslashes() removes the escaping \ from certain characters in a string. See http://us3.php.net/manual/en/function.stripslashes.php for more info on that. I believe that the escaping is turned off in the php.ini configuration on JPC servers, so that call is unnecessary.

    $_POST is an array that contains all of the variables that are posted from the form. extract() turns the elements of the array into individual variables (for example $_POST['to'] becomes $to). Again, since register_globals is on in php.ini this call is unnecessary.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  9. #9
    Loyal Client
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    387
    Originally posted by Vin DSL
    This should get you in the ballpark...

    http://us3.php.net/str-replace
    yeah.... Maybe when I've learned a bit more, that'll get me in the ballpark, lol. For now, it might as well be russian.

    Thanks anyway though, Vin. I'll refer back to that when I can understand it, lol Until then, it seems I've reached the limits of what I can do with this script, so I'll finish it further down the road.

  10. #10
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Galen,

    The "Received:" headers are added by each of the mail servers that a message passes through to get to the recipient. They are a postmark of sorts. They are added when the mail is received as opposed to when it is sent, so I doubt you'll be able to remove it from messages you send.

    When a message comes in to a mail server (whether you sent it to the server through your mail client or it came from another SMTP server on its way to its final destination) the server looks at the headers to determine what to do with it. It then adds the received header with the info about when it got there and where it came from.

    When you send mail with the php mail() function you can pass additional headers to the message by way of the fourth argument. Some headers will override server defaults (such as From. Others, such as CC: and BCC: allow you to specify additional recipients not included in the "to" argument. Anything else just gets sent along as plain text that the recipient will see if they "view all headers." In your case you could add a Received: header but in the final email it would show along with any that were added by the SMTP servers, it wouldn't override them.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  11. #11
    Loyal Client
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    387
    Spammers don't seem to have a problem doing it

    Anyway... the more I try to learn php the more I want to kick something, lol. I just don't have a mind for code (any code). I only learned html incidentally from seeing it so much over the course of several years. I wasn't actually trying to learn it, I just picked it up. Everytime I had ever tried to learn it before, I was left dumbfounded. It'll probably work the same way with php. I'll pick it up eventually, but if I keep trying to learn it intentionally, I'll never get it.

    Any type of code just makes my brain shut down, lol. Thanks for the help anyway though.

  12. #12
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,661
    Originally posted by Galen
    Anyway... the more I try to learn php the more I want to kick something, lol...

    Any type of code just makes my brain shut down, lol. Thanks for the help anyway though.
    I guess you're looking for some sort of social reinforcement here...

    Galen, I'm sure you've been told you are special all your life, only to find out that you don't have what it takes. Either that, or you thought you were special and found out otherwise.

    Well, forget all that crap and get yourself together. PHP is an art, like all coding. Logic plays a part, but it's mostly irrational. If you think you can learn PHP, you're crazy.

    HTML, CGI and Perl are dead-men-walking. PHP is a direct replacement for all three. HTML, by itself, doesn't mean shucks. If you only have experience with HTML, you're basically screwed, but don't let that stop you.

    If you really want to code in PHP, study CGI/Perl and it will make a lot more sense. Once you put that together with what you know about HTML, then it will start to make sense. That's when you can start living on the edge; even become world famous, if you figure it out.

    There are only a handful of 'us' out there that have what it takes, at this point. If you start now, by spending a few hours a day studying the things I mentioned above, then you'll be world-class in no time. If you can't find it in yourself to do this, then you're going to have to depend on ppl like me, or Googlemeisters like jason to lead you around by your nose.

    Sorry for sounding like a prick, but I tell it like it is. Hang in there and it will start making sense at some point, and it's worth the effort 'cause PHP is the future of the web. However, if you think you're going to be a PHP programmer overnight, by reasoning things out, you're going to be disappointed. You gotta have it in your ass!
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL 2010

  13. #13
    Loyal Client
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    387
    I guess you're looking for some sort of social reinforcement here...
    No, just stating the facts. No deep inner-meanings here; I don't work that way.

    Galen, I'm sure you've been told you are special all your life, only to find out that you don't have what it takes. Either that, or you thought you were special and found out otherwise.
    LOL! Nice, but you should stick to using those "shocking tell-it-like-it-is" tactics on people who have no self-esteem and no ego to speak of. I've got a big one, my friend I'm sure that was meant to illicit some type of response or great revelation on my part... It didn't.

    Well, forget all that crap and get yourself together. PHP is an art, like all coding. Logic plays a part, but it's mostly irrational. If you think you can learn PHP, you're crazy.
    Actually, I said exactly that. I'll never learn any type of coding. I just have to pick it up over time and with experience. I'm the same way with spoken languages. There's just no way to be taught those things, you either get it or you don't. Right now, I don't. In time, I will. I'm in no hurry.

    If you only have experience with HTML, you're basically screwed, but don't let that stop you.
    It never has

    If you can't find it in yourself to do this, then you're going to have to depend on ppl like me, or Googlemeisters like jason to lead you around by your nose.
    And this is why most php n00bs hate asking for help. They're left with the impression that it's just such a terrible burden for you wise people to stoop down to our level and "lead us by the nose." Get over it. You know a programming language; it doens't make you special. It just makes you someone who has knowledge that others don't. This is precisely the reason I don't belong to any PHP "help" sites. They're like places for you l33t ppl to sit around and say "hey, look at us, we know all you wish to know and if you kiss our asses enough, we might just share a tiny bit of knowledge with you." Sorry, I don't work that way either. You're not special and you're not better than anyone. I'm not talking about you personally, Vin, I'm talking about the entire community of PHP "Gurus." The arrogance among you is astounding, to say the least.

    Sorry for sounding like a prick, but I tell it like it is.
    No need to be "sorry" with me. I quite prefer "pricks" who tell it straight instead of sugar-coating their crap. While others here may be "offended" by your usual style, you needn't worry about that with me. I'm a kindred spirit, Vin, and also don't believe in sugar-coating the facts just to spare someone's poor little feelings (boo hoo).

    Anyway, I will learn when I learn and not before. I'm not interested in pushing it; it'll come. It always does

  14. #14
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Galen,

    Rest asured that not all PHP programmers are pricks and some of us actually are very willing to go out of our way to help a n00b. I've actually serendipitously learned a few things about PHP by trying to help others through problems.

    I work with many brilliant people--PhD's; folks who are tops in their fields; able to secure millions in research grants for projects that simply bewilder me. How many of them do you think can program a simple PHP script? How many of them do you think give a rats behind that they can't? Likewise, I'd be bored to tears if I had to spend years studying some of the stuff that they do. Does any of that make them better than I or me better than them? Who knows, who cares.

    If you want to learn PHP, I wish you the best of luck. The best way to do it is to learn at your own pace and don't be afraid to ask for help when you get stuck (finding the right place to ask helps, though). It can take a lot of patience to master a programming language (or any language for that matter), but if you're willing to stick with it you'll eventally get it.

    For the past few years I've been taking American Sign Languge classes for work. I can sit through an entire class and feel completely lost, like I know absolutely nothing about the language. But then, when I sit down with a deaf student and start having a converstaion it all comes back and I surprise myself in how well it goes. PHP for you will likely be the same way, you'll feel lost and then suddenly one day you'll have an epiphany and it will all start making sense.

    But then what do I know? I'm only a "Googlemeister," what ever that's supposed to mean.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  15. #15
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,414
    Originally posted by jason
    ...you'll feel lost and then suddenly one day you'll have an epiphany and it will all start making sense.
    This sounds EXACTLY like my middle school geometry proofs - confusing as heck and then, almost literally, poof! It all made sense. I wish I had that much luck with programming too.

    As far as "Googlemeisters", [Indeterminate slang. googlelicious. See Google.*] definition of, try Google. Pretty vacuous as far as searches go despite its inherent catchy cleverness.

    *Sourced from The Nonexistent Dictionary of Online Euphemisms, First Edition Copyright 2004 by Cyberspace Silliness Inc.
    Published by Anonymous Driveller. All rights reserved.

Page 1 of 2 1 2 LastLast

Bookmarks

Posting Permissions

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