0

我有一个 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.";
?>
4

2 回答 2

2

php 不使用“+”添加字符串使用“。” 用于连接字符串。

这是固定代码:

<?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.";
?>
于 2013-10-12T22:50:41.600 回答
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

http://codepad.org/1aYvxjiC

于 2013-10-13T00:00:29.437 回答