douxueke5653 2012-03-12 22:24
浏览 335
已采纳

变量中有多个$ _POST变量

Hey I have this code that sends an email with some data sent by a form:

<?php

  if (isset($_POST['submit'])) {

    error_reporting(E_NOTICE);

    function valid_email ($str) {
      return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
    }

    if ($_POST['name'] != '' &&  $_POST['email'] != '' && $_POST['tel'] != '' && valid_email($_POST['email']) == TRUE && strlen($_POST['comment']) > 1) {

      $to = preg_replace("([
])", "", $_POST['receiver']);
      $from = preg_replace("([
])", "", $_POST['name']);
      $subject = 'Online Message';
      $message = $_POST['comment'];
      $match = "/(bcc:|cc:|content\-type:)/i";
      if (preg_match($match, $to) || preg_match($match, $from) || preg_match($match, $message) || preg_match($match, $subject)) {
        die("Header injection detected.");
      }

      $headers = "From: \"".$_POST['name']."\" <".$_POST['email'].">
";
      $headers .= "Reply-to: ".$_POST['email']."
";

      if (mail($to, $subject, $message, $headers)) {
        echo 1; //SUCCESS
      } else {
        echo 2; //FAILURE - server failure
      }

    } else {
      echo 3; //FAILURE - not valid email
    }

  } else {
    die("Direct access not allowed!");
  }

I want to add the $_POST['tel'] to the $message variable so in the body of the email I can get the message plus the telephone that people type into the form. In the first part of the code I think I made the telephone input obligatory.

I tried doing $message = $_POST['comment'] && $_POST['tel']; but the only thing I recieve is a 1 in the body of the mail that is the first number of the telephone entered.

  • 写回答

2条回答 默认 最新

  • dsfdsf21321 2012-03-12 22:29
    关注

    $message = 'Comment: ' . $_POST['comment'] . ' Tel: ' . $_POST['tel'];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题