javascript - 我可以将 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 代码中的变量并发送给经理进行批准。
请问这可以工作吗?如果不能,还有其他方法可以使它工作吗?
解决方案
$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>";
推荐阅读
- postgresql - Mikro-orm 错误:用户“postgres”的密码验证失败
- python - 错误:关键应用程序无法获取窗口,中止
- javascript - JavaScript/TypeScript 如何像在 Java 中一样构建 OffsetDateTime?
- postgresql - 优化两个大表之间非常慢的 PostgreSQL LEFT JOIN
- python - argparse 参数值前缀为 --
- java - Kotlin 从 map 中按键获取值
- javascript - 如何使用javascript fetch在HTML网页中显示rest api GET
- r - 手动从图例中删除级别,同时保留数据中不存在的级别
- python - Discord.py Bot 每天特定时间运行功能
- google-sheets - 如何将表单响应列表转换为汇总表?