uwictech Posted October 27, 2009 Share Posted October 27, 2009 Hi all, I have put together 2 separate bits of code. The 1st part generates a random password and the 2nd part is an email form. I would like to echo the password into the message box of the email form so that I can email users. I could easily do this if the password were a variable but to show the password I'm echoing the function. Jamie <?php function randomPass ($cut) { $string = md5(time()); $string = substr($string , 0 , $cut); return $string; } echo randomPass(; ?> <?php if ($_POST['submit']);{ $name = $_POST['name']; $message = $_POST['message']; } if ($name&&$message) { if (strlen($name)<=20&&strlen($message)<=300); { ini_set("SMTP", "e2k3vs01.internal.uwic.ac.uk"); $to = "[email protected]"; $subject = "TEST"; $headers ="From: [email protected]"; $body = "Email From $name\n\n$message\n\n "; mail($to, $subject, $body, $headers); die(); } } ?> <html> <form action="email.php" method="POST"> Name: <input type ="test" name="name" maxlength="20"><br> Message: <br> <textarea name="message"></textarea><p> <input type="submit" name="submit" value="Send me this"> </form> </html> Link to comment https://forums.phpfreaks.com/topic/179168-solved-echo-a-function-to-a-text-box/ Share on other sites More sharing options...
Bricktop Posted October 27, 2009 Share Posted October 27, 2009 Hi uwictech, The simplest way would be to call the function inside the $body line. For example: <?php function randomPass ($cut) { $string = md5(time()); $string = substr($string , 0 , $cut); return $string; } echo randomPass(; ?> <?php if ($_POST['submit']);{ $name = $_POST['name']; $message = $_POST['message']; } if ($name&&$message) { if (strlen($name)<=20&&strlen($message)<=300); { ini_set("SMTP", "e2k3vs01.internal.uwic.ac.uk"); $to = "[email protected]"; $subject = "TEST"; $headers ="From: [email protected]"; $body = "Email From $name\n\n$message\n\n".randomPass(."\n\n "; mail($to, $subject, $body, $headers); die(); } } ?> <html> <form action="email.php" method="POST"> Name: <input type ="test" name="name" maxlength="20"><br> Message: <br> <textarea name="message"></textarea><p> <input type="submit" name="submit" value="Send me this"> </form> </html> Hope this helps. Link to comment https://forums.phpfreaks.com/topic/179168-solved-echo-a-function-to-a-text-box/#findComment-945270 Share on other sites More sharing options...
uwictech Posted October 27, 2009 Author Share Posted October 27, 2009 So simple when you know how! Thanks once again! Jamie Link to comment https://forums.phpfreaks.com/topic/179168-solved-echo-a-function-to-a-text-box/#findComment-945287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.