douzhu1188 2011-12-01 09:30
浏览 32
已采纳

使用require字段从电子邮件发送所有数据

I'm creating a user require form in my site. For this I put some validation on compulsory fields, and when a user fills in the form and presses submit and validation is correct then I receive a email on my email address.

But now I would like all user information in the email, like name, city, budget etc... so what changes do I need to make in my email.php script?

If some fields are not compulsory and the user doesn't fill them in, can they affect my script?

My script is:

<?php

  $to = "test@networkers.in";
  $subject = "a new requiremnet come!";
  $message = "Hi,

you get a new require";

  $headers = "MIME-Version: 1.0" . "
";
  $headers .= "Content-type:text/html;charset=iso-8859-1" . "
";
  $headers .= "Sender-IP: " . $_SERVER["SERVER_ADDR"] . "
";
  $headers .= "From: " . stripslashes($name) . " <" . $email . ">" . "
";
  $headers .= "Priority: normal" . "
";
  $headers .= "X-Mailer: PHP/" . phpversion();

  $sent = mail($to, $subject, $message, $headers) ;

  if ($sent) {
    echo "Your mail was sent successfully";
  } else {
    echo "We encountered an error sending your mail";
  }

?>

and the data I recieve is:

$name = $_POST['fname'].' '.$_POST['lname'];
$email = $_POST['mail'];
$phone = $_POST['ph'];
$country = $_POST['country'];
$pt = $_POST['pt'];
$cwl = $_POST['cwl'];
$dyhyows = $_POST['dyhyows'];
$pb = $_POST['pb'];
$bpd = $_POST['bpd'];
$hdyhau = $_POST['hdyhau'];
  • 写回答

1条回答 默认 最新

  • doupo1908 2011-12-01 10:19
    关注

    You can add fields to the message body by concatenating them like so:

    $message = "Hi,
    
    you get a new require";
    $message .= "
     Name:    " . $name;
    $message .= "
     Email:   " . $email;
    $message .= "
     Phone:   " . $phone;
    $message .= "
     Country: " . $country;
    $message .= "
     pt:      " . $pt;
    $message .= "
     cwl:     " . $cwl;
    $message .= "
     dyhyows: " . $dyhyows;
    $message .= "
     pb:      " . $pb;
    $message .= "
     bpd:     " . $bpd;
    $message .= "
     hdyhau:  " . $hdyhau
    

    Any fields that weren’t filled in by the user will simply be blank.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备