我对PHP很陌生,所以要温和。
看来我不能在 PHP 中运行 HTML。
例如,当我尝试
echo "<script> success(); </script>";
结果将是:
<script> success(); </script>
再比如:
$msg2 = "<b>Dear</b> ".$name ."'n'n" ."Thank you for your registration, we will be contacting you within 48h."."'n'n" ."Yours ....";
结果将是:
<b>Dear</b> (name of the client)
Thank you for your registration, we will be contacting you within 48h.
Yours ....
我检查了元它:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
我会给你们代码(其中一些是爱沙尼亚语)
<?php
if (isset($_REQUEST['email'], $_REQUEST['nimi'], $_REQUEST['koolitus'], $_REQUEST['telf'], $_REQUEST['kuupaev'], $_REQUEST['tingimused'])) {
$admin_email = "ville.madison@gmail.com";
$email = $_REQUEST['email'];
$koolitus = $_REQUEST['koolitus'];
$nimi = $_REQUEST['nimi'];
$kuupaev = $_REQUEST['kuupaev'];
$telf = $_REQUEST['telf'];
$marked = $_REQUEST['marked'];
$kodulehemail = "koolitused@registreerumine.ee";
$koolitaja = $_REQUEST['koolitaja'];
$beauty = "info@beautyfactory.ee";
$msg = "Koolitusele registreerumine: " . $koolitus . "'n" . "Soovitud koolitaja: " . $koolitaja . "'n'n" . " Nimi: " . $nimi . "'n" . " Email: " . $email . "'n" . " Telefon: " . $telf . "'n" . " Soovitud kuupäev (aaaa-kk-pp): " . $kuupaev . "'n'n" . "Märked: " . $marked;
$msg2 = '<b>Hea</b> ' . $nimi . "'n'n" . "Täname Teid koolitusele broneerimast, teatame Teile registreeringu kinnitamisest 48h jooksul." . "'n'n" . "Teie Beauty Factory";
mail($admin_email, "Koolitusele registreerumine", $msg, "From:" . $kodulehemail);
mail($email, "Koolitusele registreerumine", $msg2, "From:" . $beauty);
}
?>
目前,为了测试,我试图用粗体显示一个词。但是当我让它工作时,我将开始更多地编辑它,我想在 php if 语句中回显一个 javascript 函数。
我尝试使用单引号,双引号和:
nl2br(htmlentities($msg2));
都不起作用
您发送的消息不会被解释为 HTML。默认mail
函数的标头为文本/纯文本。
如果希望客户看到粗体文本,则必须在邮件头中将内容类型指定为 HTML。
<?php
// Set the content type of the email to HTML (and UTF-8)
$header = 'Content-type: text/html; charset=utf-8' . "'r'n";
// Add the from field
$header .= 'From: ' . $beauty . "'r'n";
// Send email
mail ($email, "Koolitusele registreerumine", $msg2, $header);
?>
但是,您将无法使用Javascript,因为它是受保护的客户端。PHP 不解释 Javascript,并且出于明显的安全原因,大多数邮件客户端不会执行 Javascript。
下面是如何在 php 中使用 html 标签的示例示例:
<?php
var $name = "xyz";
var $email = "xyz@gmail.com";
echo '<table border="1" style="width:20%">';
echo '<tr><th>UserName</th><th>Email</th></tr><tr><td>';
echo $name."<br>";
echo '</td><td>';
echo $email."<br>";
echo '</td></tr></table>';
?>
这是基本的php和html表格格式示例,您可以按照此编写html标签。
问题是函数 mail() 的默认内容为 text/plain,只需要$header来制作 text/html。谢谢大家的快速回答!