我有一个PHP脚本,根据用户输入的表单数据向用户发送电子邮件,但是当我在字符串中包含变量时,所有的电子邮件都是“0”
<?php
$u_name = $_POST['u_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$to = $_POST['email'];
$subject = "Site Activation";
$message = "Hello " + $u_name + ",";
$from = "admin@mytest4389.freeiz.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
答案 0 :(得分:2)
php不添加带“+”的字符串使用“。”对于concat字符串。
这是固定代码:
<?php
$u_name = $_POST['u_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$to = $_POST['email'];
$subject = "Site Activation";
$message = "Hello " . $u_name . ",";
$from = "admin@mytest4389.freeiz.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
答案 1 :(得分:0)
就像@MahdiParsa所说的那样,在PHP中,连接是用.
进行的,但你也可以去做(取决于每个人的口味):
$firstVariable = "Hey";
$secondVariable = "How are you?";
$mixedVariable1 = $firstVariable . ' Alex! ' . $secondVariable;
$mixedVariable2 = "$firstVariable Alex! $secondVariable";
$mixedVariable3 = "{$firstVariable} Alex! {$secondVariable}";
// $mixedVariable3 is the same as $mixedVariable2,
// only a different type of Variable Substitution
// Take a look at:
// http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html