简体   繁体   中英

can i use mail() for this code "<input type='text' name='current_user_first_name' value='<?php echo $current_user_firstname; ?>'>

I want to insert the following code in the message part of a php mail().

"<input type='text' id='current_user_first_name' 
name='current_user_first_name' value='<?php echo 
$current_user_firstname; ?>'>"

\ The full message will look like the following.

    $to="$managers_email";
    $subject="REQUEST FOR APPROVAL";
    $message=
    "<html>
    <head>
    <title>REQUEST FOR TIME SHEET APPROVAL</title>
    <style>

    </style>
    </head>
    <body>
    <form>
    <input type='text' id='current_user_first_name' 
    name='current_user_first_name' value='<?php echo 
    $current_user_firstname; ?>'>

   <input type='submit' value='APPROVED' 
   formaction='http://telecomsolutions.com/approved.php'>
   <input type='submit' value='DRAFT REJECT'>

    <textarea name='reject_reason' placeholder='Enter reject 
    reason' 
    id='reject_reason' rows='15' cols='30'>

    <input type='submit' value='REJECT' 
    formaction='http://telecomsolutions.com/reject.php'>

    </form>
    </body>
    </html>";
    $headers="MIME-Version: 1.0" ."\r\n";
    $headers.="Content-type:text/html;charset=UTF-8"."\r\n";
    $headers.='from:<$current_user_email>'."\r\n";

    mail($to,$subject,$message,$headers);
    echo "Your request submitted successfully"      
    ?>

Each time a client submits a request for approval the details of the client will be fetched from the database, used in place of the variables in the html code and sent to the Manager for approval.

Please can this work and if not,any other way to make it work?

  $variable = "John Doe";
  $message = "Hi " . $variable . " , How are you?";

The above will result in Hi John Dow, How are you?

You won't do like this

  $variable = "John Doe";
  $message = "Hi <?php echo  $variable ?> , How are you?";

The first mistake you are doing is using <?php again inside your PHP file. Then the second mistake is to use echo inside your above mentioned <php

Correct $message will be

$message=
          "<html>
              <head>
                <title>REQUEST FOR TIME SHEET APPROVAL</title>
                <style>
                </style>
              </head>
              <body>
                <form>
                  <input type='text' id='current_user_first_name' name='current_user_first_name' value='" .   $current_user_firstname . "'>

                  <input type='submit' value='APPROVED'  formaction='http://telecomsolutions.com/approved.php'>
                  <input type='submit' value='DRAFT REJECT'>
                  <textarea name='reject_reason' placeholder='Enter reject reason' id='reject_reason' rows='15' cols='30'>
                  <input type='submit' value='REJECT' formaction='http://telecomsolutions.com/reject.php'>
                </form>
              </body>
          </html>";

The above one still looks complex and difficult to manage.

You can use concatenation ( . )

$message="<html>"
          .    "<head>"
          .      "<title>REQUEST FOR TIME SHEET APPROVAL</title>"
          .      "<style>"
          .      "</style>"
          .    "</head>"
          .    "<body>"
          .      "<form>"
          .        "<input type='text' id='current_user_first_name' 
                     name='current_user_first_name' 
                     value='" .   $current_user_firstname . "'>"

          .        "<input type='submit' value='APPROVED'  formaction='http://telecomsolutions.com/approved.php'>"
          .        "<input type='submit' value='DRAFT REJECT'>"
          .        "<textarea name='reject_reason' placeholder='Enter reject reason' id='reject_reason' rows='15' cols='30'>"
          .        "<input type='submit' value='REJECT' formaction='http://telecomsolutions.com/reject.php'>"
          .      "</form>"
          .    "</body>"
          . "</html>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM