【问题标题】:String interpolation doesn't work in php字符串插值在 php 中不起作用
【发布时间】:2017-11-27 04:45:50
【问题描述】:

我很困惑。 我有两个具有相似代码的 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);

?>

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

<?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);

?>
第一个输出 名称:$nom
认知:$cog
北约伊利诺伊州 : $nato
INDIRIZZO: $ind
上限:$上限
CITTA: $cit 第二个正确输出变量的内容

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

【问题讨论】:

  • “PS:我正在使用 Wordpress 和 phpeverywhere 将 php 插入 wp 页面” - 所以基本上你所说的是,你选择了最糟糕的创建方式联系表格(?),而不是使用为工作而构建的工具,例如wordpress.org/plugins/contact-form-7 ...?
  • 我尝试了联系表格 7,但它无法将数据发送到数据库。

标签: php interpolation


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多