,javascript,php,html,css,mysql"/>

首页 > 解决方案 > 我可以将 mail() 用于此代码吗?

问题描述

我想在 php mail() 的消息部分插入以下代码。

"<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 代码中的变量并发送给经理进行批准。

请问这可以工作吗?如果不能,还有其他方法可以使它工作吗?

标签: javascriptphphtmlcssmysql

解决方案


  $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 文件中再次使用。然后第二个错误是echo在你上面提到的里面使用<php

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

推荐阅读