Jump to content

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 = "jhancock@uwic.ac.uk";
            $subject = "TEST";
            $headers ="From: telephonedatabase@uwic.ac.uk";


            
            $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 = "jhancock@uwic.ac.uk";
            $subject = "TEST";
            $headers ="From: telephonedatabase@uwic.ac.uk";


            
            $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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.