我需要一个可以给自己发送副本的复选框。例如,他们填写了联系表格并希望将副本发送给他们自己,他们选中该框,它将通过电子邮件发送给我,并且仍然通过电子邮件发送给他们。这是我的PHP:
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['weburl']) == '') {
$site = trim($_POST['weburl']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'myemail@domain.com'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nSite: \n\nComments:\n $comments";
$headers = 'From: BTSyncrets Contact <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
这是我的联系表格代码:
<div id="contact" class="offset4 login">
<form style="margin-top: 5% !important;" method="post" action="index.php" id="contactform">
<fieldset class="well">
<br>
<div class="clearfix">
<label for="name">
Your Name<span class="help-required">*</span>
</label>
<div class="input">
<input type="text" id="boxblack" name="contactname" id="contactname" value="" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="email">
Your Email<span class="help-required">*</span>
</label>
<div class="input">
<input type="text" id="boxblack" name="email" id="email" value="" class="span6 required email" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="weburl">
Your Website
</label>
<div class="input">
<input type="text" id="boxblack" name="weburl" id="weburl" value="" class="span6 required url" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="subject">
Subject<span class="help-required">*</span>
</label>
<div class="input">
<select name="subject" id="boxblack" id="subject" class="span6 required" role="select" aria-required="true">
<option></option>
<option>One</option>
<option>Two</option>
</select>
</div>
</div>
<div class="clearfix">
<label for="message">Message<span class="help-required">*</span></label>
<div class="input">
<textarea rows="8" id="boxblack" style="resize: none;" name="message" id="message" class="span6 required" role="textbox" aria-required="true"></textarea>
</div>
</div>
<label class="checkbox">
<input type="checkbox" name="copy" value="1" /> Send Yourself a copy
</label>
<div class="actions">
<input type="submit" value="Send Your Message" name="submit" id="submitButton" class="btn btn-inverse" title="Click here to submit your message!" />
<input type="reset" value="Clear Form" class="btn btn-danger" title="Remove all the data from the form." />
</div>
</fieldset>
</form>
</div><!-- form -->