mail function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • maya

    mail function

    I'm learning how to send mail with php...

    only thing that mystifies me a bit is I can't get NAME of sender to
    appear in e-mail INBOX under "from"... I only see e-mail address.. I'm
    coming from Java, with Java you can set it up so whatever user puts
    under "name" in the form you can grab and in e-mail INBOX under "from"
    you see sender's name, not e-mail address.. I would like to be able to
    do this with php.. I've looked at various tutorials, and so far can't
    see how you can do this.. thank you..

    -m
  • Bent Stigsen

    #2
    Re: mail function

    maya wrote:
    [color=blue]
    > I'm learning how to send mail with php...
    >
    > only thing that mystifies me a bit is I can't get NAME of sender to
    > appear in e-mail INBOX under "from"... I only see e-mail address.. I'm
    > coming from Java, with Java you can set it up so whatever user puts
    > under "name" in the form you can grab and in e-mail INBOX under "from"
    > you see sender's name, not e-mail address.. I would like to be able to
    > do this with php.. I've looked at various tutorials, and so far can't
    > see how you can do this.. thank you..[/color]

    If you use the mail-function, then there is an example of this in the
    manual.


    From "Example 4.":
    $headers .= 'From: Birthday Reminder <birthday@examp le.com>' . "\r\n";


    /Bent

    Comment

    • maya

      #3
      Re: mail function

      Bent Stigsen wrote:[color=blue]
      > maya wrote:
      >
      >[color=green]
      >>I'm learning how to send mail with php...
      >>
      >>only thing that mystifies me a bit is I can't get NAME of sender to
      >>appear in e-mail INBOX under "from"... I only see e-mail address.. I'm
      >>coming from Java, with Java you can set it up so whatever user puts
      >>under "name" in the form you can grab and in e-mail INBOX under "from"
      >>you see sender's name, not e-mail address.. I would like to be able to
      >>do this with php.. I've looked at various tutorials, and so far can't
      >>see how you can do this.. thank you..[/color]
      >
      >
      > If you use the mail-function, then there is an example of this in the
      > manual.
      > http://dk2.php.net/manual/en/function.mail.php
      >
      > From "Example 4.":
      > $headers .= 'From: Birthday Reminder <birthday@examp le.com>' . "\r\n";
      >
      >
      > /Bent[/color]

      thank you very much Bent...

      I have:

      $sendername = $_GET['name'];
      $email = $_GET['email'];
      $headers = 'From: $sendername <$email>' . "\r\n";

      in email INBOX it says from $sendername (literally, does not print name...)

      if I do

      $headers .= 'From: $sendername <$email>' . "\r\n";

      (add the '.' right before '=' like in example you cited..)
      I get an error (undefined var in line where $header var is declared..)

      I'm new to php.. and I would like to know, please, why is there a '.'
      sometimes before '='.. what is this for.. (it's not working for me right
      now, though..)

      one thing that I find weird about php is how you can print vars inside
      or outside quotes... i.e., if I want to print a variable with some html
      I have to include in quotes not only the html (which makes sense), but
      also the variable, for example:

      echo $x; // if I want to add some html here I have to do

      echo "$x<br>"; // I think this is very weird..

      I'm used to Java, in which you would do:

      out.print(varNa me + "<br>"); // :)

      thank you very much....






















      Comment

      • Super_Lopez

        #4
        Re: mail function


        maya ha comentado:[color=blue]
        > I'm new to php.. and I would like to know, please, why is
        > there a '.' sometimes before '='.. what is this for [..][/color]

        This is for link together (concatenate[1]) the previous content
        in that var with the current assignment.

        About the variables, you can use simple quotes (') instead of
        double quotes ("), and then you won't see expanded this variables.
        These, and a lot of other concepts, are clearly explaind in the
        php docs[2].


        [1] http://www.php.net/manual/en/languag...assignment.php
        [2] http://www.php.net/manual/en/language.types.string.php

        Regards.

        Comment

        • maya

          #5
          Re: mail function

          Super_Lopez wrote:[color=blue]
          > maya ha comentado:[color=green]
          > > I'm new to php.. and I would like to know, please, why is
          > > there a '.' sometimes before '='.. what is this for [..][/color]
          >
          > This is for link together (concatenate[1]) the previous content
          > in that var with the current assignment.
          >
          > About the variables, you can use simple quotes (') instead of
          > double quotes ("), and then you won't see expanded this variables.
          > These, and a lot of other concepts, are clearly explaind in the
          > php docs[2].
          >
          >
          > [1] http://www.php.net/manual/en/languag...assignment.php
          > [2] http://www.php.net/manual/en/language.types.string.php
          >
          > Regards.[/color]

          muchas gracias Super Lopez! :)

          I understand now how this works..

          echo "$x<br>";

          since you don't escape '$' php knows it's a variable (how does it know
          when var name ends though.. since here there's no space between end of
          var name and the rest..) will certainly look at urls you suggest..
          again muchas gracias....



          Comment

          • Bent Stigsen

            #6
            Re: mail function

            maya wrote:[color=blue]
            > Super_Lopez wrote:[/color]
            [snip][color=blue][color=green]
            >> [2] http://www.php.net/manual/en/language.types.string.php
            >>
            >> Regards.[/color]
            >
            > muchas gracias Super Lopez! :)
            >
            > I understand now how this works..
            >
            > echo "$x<br>";
            >
            > since you don't escape '$' php knows it's a variable (how does it know
            > when var name ends though.. since here there's no space between end of
            > var name and the rest..) will certainly look at urls you suggest..
            > again muchas gracias....[/color]

            It's a good observation. I guess you have seen how to resolve it from the
            link above, but I just wanted to add that it (ambiguities) is in general
            something, that one should be watchful of, and verify how it is
            interpretated.

            To quote from a comment on another language; "The programmer is always
            assumed to know what he is doing and is not hemmed in by petty
            restrictions."

            That is quite true for PHP, but unfortunately PHP's interpretation is not
            allways intuitive.

            Take for instance:

            $a = 'hello_world';
            $hello_world['en'] = "Hello World\n";
            $hello_world['es'] = "Hola mundo\n";
            $hello_world['dk'] = "Hej verden\n";

            //This will give you the array of strings, $hello_world
            print_r($$a);

            //but, this will not give you $hello_world['en']
            echo $$a['en'];

            //however, this will
            echo ${$a}['en'];


            There was a thread a couple of weeks ago called "Butt ugly", with perhaps a
            more common "mistake", one might make.



            /Bent

            Comment

            Working...