我创建了一个简单的联系表单,需要添加用户通过电子邮件提交向我发送一些图像的功能。这是表格:
<form name="submission_form" method="post" action="./contact.php">
<h3>Submission</h3>
<span><input class="data" type="email" name="email" placeholder="Email"></span>
<span><input class="data" type="text" name="first_name" placeholder="First Name"></span>
<span><input class="data" type="text" name="last_name" placeholder="Last Name"></span>
<span><input class="data" type="text" name="address" placeholder="Address"></span>
<span><input class="data" type="text" name="city" placeholder="City"></span>
<span><input class="data" type="text" name="state" placeholder="State"></span>
<span><input class="data" type="text" name="zip_code" placeholder="Zip Code"></span>
<span><input class="submit" type="submit" value="Submit"></span>
</form>
这是到目前为止的contact.php文件:
<?php
if(isset($_POST['email'])) {
$email_to = "person@email.com";
$email_subject = "Mom's Submission";
function died($error) {
// error code
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['email']) ||
!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['address']) ||
!isset($_POST['city']) ||
!isset($_POST['state']) ||
!isset($_POST['zip_code'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$email = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip_code = $_POST['zip_code'];
$error_message = "";
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "You've received a submission yo!!\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "State: ".clean_string($state)."\n";
$email_message .= "Zip Code: ".clean_string($zip_code)."\n";
// 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);
?>
我试过简单地添加:
<input name="image" type="file">
到 HTML 并添加:
!isset($_POST['image'])
和
$image = $_POST['image'];
到 config.php 文件,但我不确定在那之后该怎么做以确保附件与电子邮件一起传递。任何人都可以帮忙吗?