php email. how does it know to populate certain fields
so im learning php (begginer if you cant tell) and, im currently pushin/pulling data from the db to a page so that it can then populate other parts of the page and when "send" is hit, it pu开发者_运维知识库ts it all together and sends right...
my question is,
i know to set for example:
$to = 'email@gmail.com';
$subject = 'test from my email php script';
$email = $_POST['email'];
$name = $_POST['fname'];
$lastname = $_POST['lname'];
$mssg = $_POST['mssg'];
but how does php or the mail app on the server know which field goes where since these are self made variables???
so for example if i say:
mail($to, $subject, $name, $lastname, $mssg);
how does it know to put say "subject" in the emails subject area and not all together in the mesage field etc?
i have a few pages open but none explain the WHY or better et, the HOW
thanks in advance.
The mail() function expects your arguments to it to be in a certain order, so that it knows which values are for what. Then it builds the proper email headers based on what you gave it, and passes it to the email server to send off.
p.s. - your example is wrong. mail() would return an error because of that. Take a look at the manual entry for mail() to see what it expects and where http://www.php.net/manual/en/function.mail.php
The mail()
function is defined like this :
mail ( string $to , string $subject , string $message
[, string $additional_headers [, string $additional_parameters ]] )
So, basically :
- The first parameter you pass it is who the mail is going to be sent to,
- The second parameter is the subject of the mail,
- The third one is the message,
- ...
how does it know to put say "subject" in the emails subject area and not all together in the mesage field etc?
Well, it's been coded that way -- and that's why the documentation exists : to tell you what the function expects you to pass it.
I think you are a bit confused.
the definition for the php mail function looks like this
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
so basically with your call, you have the to and the subject right, but you are using $name as the message, $lastname as the additional headers string, and $mssg as the additional parameters string. Does this make sense?
for more info on the php mail function: http://www.php.net/manual/en/function.mail.php
this won't work. third parameter should be message
//mail(TO, SUBJECT, MESSAGE, HEADERS);
mail("mail@mail.to", "Subject", "Hey! :)", "From: anonym@anonym.com");
精彩评论