jon4433 Posted February 17, 2012 Share Posted February 17, 2012 I'm using the mail() in my application form, but I can't seem to get the email to send what the user has entered in the form to me. It's been confusing me for hours now! <?php if($_POST['submit']) { $username = $_POST['username']; $email = $_POST['email']; $age = $_POST['age']; $location = $_POST['location']; $duration = $_POST['duration']; $griefed = $_POST['griefed']; $access = $_POST['access']; $builder = $_POST['builder']; $fill = $_POST['fill']; if($username && $email && $age && $location && $duration && $griefed && $access && $builder && $fill){ $to = "dtoyee@dawncraftmc.com"; $from = '$email'; $subject = "Creative World Application" ; $message = "Username: $username /n" . "Email: $email /n" . "Age: $age /n" . "Location: $location /n" . "Duration on the server: $duration /n" . "Ever griefed: $griefed /n" . "Access to the new world: $access /n" . "Are you a good builder: $builder /n" . "Anything else that we should know: $fill /n" . mail($to, $from, $subject, $message); echo "Application was sent!"; } else { echo "All fields are required!"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form method="POST"> <center> In-Game Name: <input type="text" name="username"/><p> Email: <input type="text" name="email" /><p> Age: <input type="text" name="age" /><p> Location: <input type="text" name="location" /><p> How long have you beed on Dawncraft: <input type="text" name="duration" /><p> Have you ever griefed: <input type="text" name="griefed" /><p> Why do you want access to the creative world: <input type="text" name="access" /><p> Do you consider yourself to be a good builder: <input type="text" name="builder" /><p> Anything else that we should know: <textarea name="fill"></textarea><p> <input type="submit" name="submit" value="Submit" /> </center> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/ Share on other sites More sharing options...
Maq Posted February 17, 2012 Share Posted February 17, 2012 Do I have this correct, the email sends but the variables inside the of $message do not appear? Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318396 Share on other sites More sharing options...
Pikachu2000 Posted February 17, 2012 Share Posted February 17, 2012 On this line: $from = '$email';, you assign the string literal '$email' to the $from variable. You don't need quotes at all to assign the value of a variable to another variable. The arguments in the mail function aren't right. From: is a header, not an argument by itself. Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318399 Share on other sites More sharing options...
jon4433 Posted February 17, 2012 Author Share Posted February 17, 2012 On this line: $from = '$email';, you assign the string literal '$email' to the $from variable. You don't need quotes at all to assign the value of a variable to another variable. The arguments in the mail function aren't right. From: is a header, not an argument by itself. Hmm, what will I need to do to the mail function? I thought the mail function was correct, but i'm new at php. Do I have this correct, the email sends but the variables inside the of $message do not appear? That is correct. It actually shows the $subject in the message area. Also, I like how fast replies are on this forum! Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318415 Share on other sites More sharing options...
jcbones Posted February 17, 2012 Share Posted February 17, 2012 Can't believe that script doesn't have a parse error: <?php //syntax highlighting. if($username && $email && $age && $location && $duration && $griefed && $access && $builder && $fill){ $to = "dtoyee@dawncraftmc.com"; $from = '$email'; $subject = "Creative World Application" ; $message = "Username: $username /n" . "Email: $email /n" . "Age: $age /n" . "Location: $location /n" . "Duration on the server: $duration /n" . "Ever griefed: $griefed /n" . "Access to the new world: $access /n" . "Are you a good builder: $builder /n" . "Anything else that we should know: $fill /n" . //<- You need to remove the . (period) and place a ; (semicolon). mail($to, $from, $subject, $message); Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318427 Share on other sites More sharing options...
jon4433 Posted February 17, 2012 Author Share Posted February 17, 2012 Can't believe that script doesn't have a parse error: <?php //syntax highlighting. if($username && $email && $age && $location && $duration && $griefed && $access && $builder && $fill){ $to = "dtoyee@dawncraftmc.com"; $from = '$email'; $subject = "Creative World Application" ; $message = "Username: $username /n" . "Email: $email /n" . "Age: $age /n" . "Location: $location /n" . "Duration on the server: $duration /n" . "Ever griefed: $griefed /n" . "Access to the new world: $access /n" . "Are you a good builder: $builder /n" . "Anything else that we should know: $fill /n" . //<- You need to remove the . (period) and place a ; (semicolon). mail($to, $from, $subject, $message); It did have a semicolon before I posted the thread. I was testing to try and get them to include each other, but I guess it didn't work, but i'll be changing them back to a semicolon soon! Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318429 Share on other sites More sharing options...
jcbones Posted February 17, 2012 Share Posted February 17, 2012 The correct argument list for mail is: <?php //syntax highlighting mail($to,$subject,$message,$headers); //from is a header. mail Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318445 Share on other sites More sharing options...
jon4433 Posted February 18, 2012 Author Share Posted February 18, 2012 Thank you! They are how I want it to be now! I also have another problem... How do I attach more than one string to the message? I'm only getting the 'Username' at the moment. Edit - Figured it out! Thank you for the help! Quote Link to comment https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318544 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.