我对php很新,自从我使用HTML以来已经有一段时间了。我有几个带有表单的网页,我希望将表单数据通过电子邮件发送到我的电子邮箱。我已尝试使用MAILTO
测试一些简单的html,但这并不起作用。
我还在玩一个PHP文件来通过电子邮件发送数据,但这并不起作用。有人可以提供一些真正有用的代码,或者将我引导到通过电子邮件发送表单数据的页面吗?我非常沮丧,托管服务支持毫无用处 - 他们只是说脚本不起作用。 DUH。这是我正在测试的: HTML
<html>
<body>
<form action="email_form.php?do=send" method="POST">
<p>* Required fields</p>
<?php
if ($message) echo '<p style="color:red;">'.$message.'</p>';
?>
<table border="0" width="500">
<tr><td align="right">* First Name: </td>
<td><input type="text" name="fname" size="30" value="<?php echo @$fname ?>"></td></tr>
<tr><td align="right">Middle Name: </td>
<td><input type="text" name="mname" size="30" value="<?php echo @$mname ?>"></td></tr>
<tr><td align="right">* Last Name: </td>
<td><input type="text" name="lname" size="30" value="<?php echo @$lname ?>"></td></tr>
</table>
<p>
<TEXTAREA name="fsendmail" ROWS="6" COLS="60"><?php if($fsendmail) echo $fsendmail; ?></TEXTAREA>
</td></tr>
<tr><td align="right"><input type="submit" value="Send Now">
</td></tr>
</table>
</form>
</body>
</html>
PHP
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<p><?php<br>
switch (@$_GET['do'])<br>
{<br>
<br>
case "send":<br>
<br>
$fname = $_POST['fname'];<br>
$lname = $_POST['lname'];<br>
$mname = $_POST['mname'];<br>
if (!preg_match("/\S+/",$fname))<br>
{<br>
unset($_GET['do']);<br>
$message = "First Name required. Please try again.";<br>
break;<br>
}<br>
if (!preg_match("/\S+/",$lname))<br>
{<br>
unset($_GET['do']);<br>
$message = "Last Name required. Please try again.";<br>
break;<br>
}<br>
if ($secretinfo == "")<br>
{<br>
$myemail = "jbunns@gmail.com";<br>
$emess = "First Name: ".$fname."\n";<br>
$emess.= "Middle Name: ".$mname."\n";<br>
$emess.= "Last Name: ".$lname."\n";<br>
$ehead = "From: ".$femail."\r\n";<br>
$subj = "An Email from ".$fname." ".$mname." ".$lname."!";<br>
$mailsend=mail("$myemail","$subj","$emess","$ehead");<br>
$message = "Email was sent.";<br>
}<br>
<br>
unset($_GET['do']);<br>
header("Location: thank_you.html");<br>
break;<br>
<br>
default: break;<br>
}<br>
?></p>
</body>
</html>
答案 0 :(得分:1)
尝试
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
有关它的更多信息,可能需要查看http://www.php.net//manual/en/function.mail.php