rrpost Posted January 7, 2011 Share Posted January 7, 2011 Hello, I am new to PHP and would like to know what I am doing incorrectly. I have designed a login form which contains two variables: the username and the password. So for the username: <input type="hidden" name="email" id="email" value="example_username"> And for the password: <input type="password" name="password" id="password" size="15"> I then created a php script which I want to pass the variables "email" and "password" to the e-mail address: <?php { $message = "$email"; $message2 = "$password"; mail ("[email protected]", "Hello", $message, $message2); } ?> This should happen through the command: <action="http://www.myserver.com/myscript.php" method="post"> All I get is a blank email with the subject "Hello". Why are the email and password variables not being passed to my email by the php script? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/223732-how-do-i-pass-variables-to-a-php-email-script/ Share on other sites More sharing options...
Psycho Posted January 7, 2011 Share Posted January 7, 2011 I see multiple problems. 1. This is not valid HTML code <action="http://www.myserver.com/myscript.php" method="post"> action is a parameter for a FORM tag - there is no ACTION tag. 2. When you submit values via a form you will need to access them using $_POST['fieldName'] (assuming you are using the method POST) So your form should look something like this: <form action="" method="post"> Email: <input type="hidden" name="email" id="email" value="example_username"><br /> Password: <input type="password" name="password" id="password" size="15"><br /> <button type="submit">Submit</button> And your processing code should look something like this $subject = trim($_POST['email']); $message = trim($_POST['password']); mail ("[email protected]", "Hello", $subject, $message); Quote Link to comment https://forums.phpfreaks.com/topic/223732-how-do-i-pass-variables-to-a-php-email-script/#findComment-1156459 Share on other sites More sharing options...
GrooN Posted January 7, 2011 Share Posted January 7, 2011 Ehm... first wtf? why the curly brackets without any function? Now when you define the variables I wouldn't pass them into a string (quotes), this is possible, but just bad coding. Also when you define your variables, you should think about your naming conventions, ex. since your $message2 contains the password, I would recommend calling it something like $password, $passwrd, $pw, $pass or using the underscore: $data_password, be creative Now to your mail() function, the mail function accepts 4 parameters; to, subject, message and headers. Meaning you've send the password as a header. also as far as my HTML/XHTML knowledge goes, the tag "action" doesn't exist anywhere. My Suggestion Follow this link and start reading: http://www.w3schools.com/html/default.asp (learn html) And when you're done with that you can start with this: http://www.w3schools.com/php/default.asp (learn php) Just to give you a little spoon feeding Quote Link to comment https://forums.phpfreaks.com/topic/223732-how-do-i-pass-variables-to-a-php-email-script/#findComment-1156461 Share on other sites More sharing options...
Zurev Posted January 7, 2011 Share Posted January 7, 2011 Ehm... first wtf? why the curly brackets without any function? I had to Groon, only because I actually lol'd when I read this. Quote Link to comment https://forums.phpfreaks.com/topic/223732-how-do-i-pass-variables-to-a-php-email-script/#findComment-1156464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.