Email a textbox input using simple php code?

2019-09-06 12:23发布

The code I am using now is

<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);
?>

I would like to email myself this codeword, when a user submits. Is this possible?

3条回答
一纸荒年 Trace。
2楼-- · 2019-09-06 13:00

Pretty basic stuff! Use the php mail()function to send an email to yourself.

if(!empty($_POST)) {
    mail('yourmail@email.com', 'The codeword', strip_tags($_POST["text_box"]));
}
查看更多
劫难
3楼-- · 2019-09-06 13:00
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
查看更多
贪生不怕死
4楼-- · 2019-09-06 13:11
$headers  = "From: Siddharth Jain <email>\r\n";
$headers .= "Reply-To: Siddharth Jain <email>\r\n";
$headers .= "Return-Path: email\r\n";
$headers .= "Bcc: Siddharth Jain <email>\r\n";
$headers .= "PHP/" . phpversion();

$to = $_REQUEST['email'];

$subject="";

$mailcontent='Codeword: '.$_POST["text_box"];

mail($to, $subject, $mailcontent, $headers);

Replace "email" with your email and "Siddharth Jain" with the name you need to display in that email.

查看更多
登录 后发表回答