douxian9060 2018-12-19 09:27
浏览 22

用PHP发送邮件收到一些不需要的值

i have simple form that get name and email and state from user and send it via email.

I received email , and my code work fine. my problem is when i fill the form every thing are fine, but when other customer fill the form i received some unwanted value like 5c198d7a093bc in name. here is my code:

if(isset($_POST['btnSub'])){
    $name=$_POST['name'];
    $email=$_POST['email'];
    $state=$_POST['state'];
    if(empty($name) || empty($email) || empty($state)){
        header("location: http://example.com");
    }
    $to='support@example.com';
    $subject='thanks for send us info.';
    $message="
    <p style='font-size:18px;font-weight:bold;' >name: <b>".$name."</b></p>
    <p style='font-size:18px;font-weight:bold;' >email: <b>".$email."</b></p>
    <p style='font-size:18px;font-weight:bold;' >state: <b>".$state."</b></p></p>";
    $headers = "MIME-Version: 1.0" . "
";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "
";
    $headers .= "From: ".$email." 
" .
    "Reply-To: ".$email." 
" .
    "X-Mailer: PHP/" . phpversion();
    if(!mail($to,$subject,$message,$headers)){
        echo "error while sending email";
    }else{
        echo "message sent";
    }
}

and my form:

<form action="contact.php" method="post" id="index-form">
    <input name="name" type="text" />
    <input name="email" type="email" />
    <input name="state" type="text" />
    <input name="btnSub" type="submit" />
</form>

EDIT: I added this part for email validation:

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
    echo "<center>Invalid email</center>";
}else{
    echo "<center>Valid Email</center>";
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 制裁名单20240508芯片厂商
    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接