首先,我不是程序员——所以我试图让事情适应我的需要。我已经在一个 html 表单上工作了几个星期,它产生一个唯一的代码并将数据通过电子邮件发送给我和表单所有者。
我已经设法让所有这些工作并将其构建到我的网站中。
然而,最后的痕迹是我想将电子邮件格式化为 html,并且我已经搜索并阅读并尝试了许多不同的代码 - 有些甚至从这里没有成功。我在一个不间断的句子中得到代码,什么都没有或所有信息。
这是我的 php.ini 文件。靠近底部的是我在邮件中需要的信息$email_message
表格代码:
<div style="position:absolute;left:0px;top:546px;width:350px;height:84px;">
<style type="text/css">
.formtxt{color:white;}
</style>
<?php
$tokens = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$serial = '';
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 4; $j++) {
$serial .= $tokens[rand(0, 35)];
}
if ($i < 2) {
$serial .= '-';
}
}
?>
<form name="contactform" method="post" action="bridalcontact.php">
<table width="350px" align="center">
<tr>
<td valign="top">
<label for="first_name"> <span class="formtxt">First Name*</span></label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="20">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name"> <span class="formtxt">Last Name*</span></label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="20">
</td>
</tr>
<tr>
<td valign="top">
<label for="email"> <span class="formtxt">Email*</span></label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="20">
</td>
</tr>
<tr>
<td valign="top">
<label for="security"> <span class="formtxt">What colour is the sky *</span></label>
</td>
<td valign="middle">
<input type="text" name="security" maxlength="80" size="20">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Code</label>
</td>
<td valign="top">
<input type="disabled" name="code" size="20" value='<?php echo "$serial"?>'readonly>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</div>
php代码:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "my email address here";
$email_subject = "Your AODJ voucher";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['security'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$security = $_POST['security']; // required
$code = $_POST['code']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$security_exp = "/blue/";
if(!preg_match($security_exp,$security)) {
$error_message .= 'Wrong solar system - sorry.<br />';
}
//$string_exp = "/^[A-Za-z .'-]+$/";
//if(!preg_match($security_exp,$security)) {
//$error_message .= 'Wrong solar system - sorry.<br />';
//}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "code: ".clean_string($code)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
@mail($email_from, $email_subject, $email_message, $headers);
?>
<?php
if( !empty( $_POST ) ) {
header( "Location: bridaloptionsthanks.html" ) ; exit ;
}
}
?>