使用简单的php代码通过电子邮件发送文本框输入?

使用简单的php代码通过电子邮件发送文本框输入?,php,email,input,textbox,Php,Email,Input,Textbox,我现在使用的代码是 <form name="form" method="post"> Codeword: <input type="text" name="text_box" size="50"/> <input type="submit" id="search-submit" value="submit" /> <? $a=@$_POST["text_box"]; $myFile = "t.txt"; $fh = fopen($myFile, 'w')

我现在使用的代码是

<form name="form" method="post">
Codeword: <input type="text" name="text_box" size="50"/>
<input type="submit" id="search-submit" value="submit" />
<?
$a=@$_POST["text_box"];
$myFile = "t.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,$a);
fclose($fh);
?>

码字:

相当基本的东西!使用php函数向您自己发送电子邮件

if(!empty($_POST)) {
    mail('yourmail@email.com', 'The codeword', strip_tags($_POST["text_box"]));
}
$headers=“From:Siddharth Jain\r\n”;
$headers.=“回复:Siddharth Jain\r\n”;
$headers.=“返回路径:电子邮件\r\n”;
$headers.=“密件抄送:Siddharth Jain\r\n”;
$headers.=“PHP/”。phpversion();
$to=$_请求['email'];
$subject=“”;
$mailcontent='Codeword:'.$\u POST[“文本框”];
邮件($to、$subject、$mailcontent、$headers);
将“email”替换为您的电子邮件,“Siddharth Jain”替换为您需要在该电子邮件中显示的名称

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $num))
_


是的,您试图实现它的目的是什么?您忘记了表单中的
action=”“
。假设您在可以发送邮件的服务器上运行此操作,我看不出为什么不可以。出于安全原因(防止恶意HTML),您可能希望执行
strip\u标记($\u POST[“text\u box]”)
。使用mail()函数发送邮件!这太疯狂了,它可能会工作谢谢我不太懂PHP,仅此而已:)它可以工作,但有可能在网页加载时不发送电子邮件吗?仅在按下提交按钮的实例上?您的答案存在格式问题。你能修一下吗?
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $num))
error: Deprecated: Function eregi() is deprecated in C:\wamp\www\chk\email\emailval.php on line 8