簡體   English   中英

我可以將 mail() 用於此代碼嗎? <input type="text" name="current_user_first_name" value="<?php echo $current_user_firstname; ?>">

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

我想在 php 郵件()的消息部分插入以下代碼。

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

\ 完整的消息將如下所示。

    $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"      
    ?>

每次客戶提交審批請求時,都會從數據庫中獲取客戶的詳細信息,用於代替 html 代碼中的變量並發送給經理進行審批。

請問這可以工作嗎?如果不能,還有其他方法可以使它工作嗎?

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

以上將導致Hi John Dow, How are you?

不會這樣

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

您犯的第一個錯誤是在 PHP 文件中再次使用<?php 然后第二個錯誤是在上面提到的<php中使用echo

正確的$message將是

$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>";

上面的一個看起來仍然很復雜且難以管理。

您可以使用串聯 ( . )

$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>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM