Jump to content

[SOLVED] ECHO a function to a text box?


uwictech

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.