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条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器