字符串插值在php中不起作用

时间:2017-06-23 14:43:55

标签: php interpolation

我很困惑。 我有两个类似代码的php页面,一个没有。 问题是脚本打印变量名称而不是其内容 一个不起作用



<?php
$cod=htmlspecialchars($_POST["codice"]);
$nom=htmlspecialchars($_POST["nome"]);
$cog=htmlspecialchars($_POST["cognome"]);
$nato=htmlspecialchars($_POST["nato"]);
$ind=htmlspecialchars($_POST["indirizzo"]);
$cap=htmlspecialchars($_POST["cap"]);
$cit=htmlspecialchars($_POST["citta"]);
$pro=htmlspecialchars($_POST["provincia"]);
$cf=htmlspecialchars($_POST["cf"]);
$tel=htmlspecialchars($_POST["tel"]);
$mail=htmlspecialchars($_POST["mail"]);
$classe=htmlspecialchars($_POST["classe"]);
$scelta=htmlspecialchars($_POST["radio"]);
$pagamento=htmlspecialchars($_POST["pagamento"]);
$ipad=htmlspecialchars($_POST["ipad"]);
$colore=htmlspecialchars($_POST["colore"]);

//INVIO MAIL 
$to = "xxxi@xxx.xx";
$subject = "SOGGETTO";

$message = "
<html>
<head>
<title>TITOLO</title>
</head>
<body>
<p>TITOLO</p>
CODICE ISCRIZIONE: $cod 
<br /> NOME: $nom 
<br /> COGNOME: $cog 
<br /> NATO IL : $nato 
<br /> INDIRIZZO: $ind 
<br /> CAP : $cap 
<br /> CITTA: $cit 
<br /> PROVINCIA: $pro 
<br /> TELEFONO: $tel 
<br /> CF: $cf 
<br /> SCELTA: $scelta 
<br /> MAIL: $mail 
<br /> ULTIMA CLASSE CON SUCCESSO: $classe 
<br /> MODALITA DI PAGAMENTO: $pagamento 
<br /> IPAD: $ipad 
<br /> COLORE IPAD: $colore 
<br /> ACCETTO IL CONTRATTO = SI
<br /> FINE DEL MESSAGGIO
</body>
</html>
";

// Always set content-type when sending HTML email
// More headers
$headers = "From: xx@xx.xx\r\n";
$headers .= "Reply-To: xx@xx.xx\r\n";
$headers .= "Return-Path: xx@xx.xxt\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);

?>
&#13;
&#13;
&#13;

但我有另一个有效的脚本,似乎是平等的。 不知道为什么。

&#13;
&#13;
<?php
$nome=htmlspecialchars($_POST["nome"]);
$cognome=htmlspecialchars($_POST["cognome"]);
$sesso=htmlspecialchars($_POST["sesso"]);
$giorno=htmlspecialchars($_POST["giorno"]);
$mese=htmlspecialchars($_POST["mese"]);
$anno=htmlspecialchars($_POST["anno"]);
$citta=htmlspecialchars($_POST["citta"]);
$email=htmlspecialchars($_POST["email"]);
$tel=htmlspecialchars($_POST["tel"]);
$corsofrequentato=htmlspecialchars($_POST["corsofrequentato"]);
$ultimaclasse=htmlspecialchars($_POST["ultimaclasse"]);
$corsodafrequentare=htmlspecialchars($_POST["corsodafrequentare"]);
$primo=htmlspecialchars($_POST["primo"]);
$secondo=htmlspecialchars($_POST["secondo"]);
$terzo=htmlspecialchars($_POST["terzo"]);
$quarto=htmlspecialchars($_POST["quarto"]);
$quinto=htmlspecialchars($_POST["quinto"]);
setlocale(LC_TIME, 'ita');
$oggi=strftime("%Y%m%d");
$adesso=date("9His");
$keyword="2";
//Invio MAIL 
$to = "xxx@xxx.xxx";
$subject = "soggetto";

$message = "
<html>
<head>
<title>TITOLO</title>
</head>
<body>
<p>SOGGETTO </p>
<br /> NOME: $nome
<br /> COGNOME: $cognome
<br /> SESSO: $sesso
<br /> DATA DI NASCITA: $giorno/$mese/$anno
<br /> CITTA': $citta
<br /> EMAIL: $email
<br /> TEL: $tel
<br /> ULTIMO CORSO: $corsofrequentato
<br /> ULTIMA CLASSE: $ultimaclasse
<br /> CORSO RICHIESTO: $corsodafrequentare
<br /> PRIMA: $primo
<br /> SECONDA: $secondo
<br /> TERZA: $terzo
<br /> QUARTA: $quarto
<br /> QUINTA: $quinto
<br /> DATA RICHIESTA: $oggi
<br /> ORA RICHIESTA: $adesso
<br /> PAROLA CHIAVE: $keyword

</body>
</html>
";

// Always set content-type when sending HTML email
// More headers
$headers = "From: xxx@xxx.xx\r\n";
$headers .= "Reply-To: xxx@xxx.xx\r\n";
$headers .= "Return-Path: xxx@xxx.xx\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);

?>
&#13;
&#13;
&#13; 第一个输出 NOME:$ nom     
COGNOME:$ cog     
北约IL:$ nato     
INDIRIZZO:$ ind     
CAP:$ cap     
CITTA:$ cit 第二个正确输出变量

的内容

有人可以帮助我吗? 谢谢。 P.S。:我正在使用WordPress将php插入wp页面

1 个答案:

答案 0 :(得分:0)

解决: 问题是prev页面上的表单。它没有发送正确的值,而是发送变量的名称,因此我确信错误发生在结果页面中。 所以代码是正确的,如果有人需要它。 谢谢大家。