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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测