我是网页设计的新手。我需要在 HTML 中创建一个表单,以便它要求用户输入几个字段并上传他/她的简历。当他提交表格时,他的提交应该通过电子邮件发送给我,并附上他的简历作为电子邮件的附件。我使用 PHP 发送电子邮件。一切正常,除了文件没有随发送的电子邮件附加。
我发布了 HTML 和 PHP 代码,请帮助我..
HTML 代码:文件名:Careers.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form</title>
</head>
<body>
<form action="Careers.php" method="post" enctype="multipart/form-data">
Name<br>
<input type="text" name="cf_name"><br>
E-mail<br>
<input type="text" name="cf_email"><br>
Date of Birth<br>
<input type="text" name="db_name"><br>
Contact Number<br>
<input type="text" name="db_cntct"><br>
Class 12 Marks/CGPA/Percentage<br>
<input type="text" name="cf_board"><br>
Graduation Marks/CGPA/Percentage<br>
<input type="text" name="db_grad"><br>
Post-Graduation Marks/CGPA/Percentage<br>
<input type="text" name="cf_pgrad"><br>
Present Employer<br>
<input type="text" name="db_emplyr"><br>
Date of Joining<br>
<input type="text" name="cf_doj"><br>
Designation<br>
<input type="text" name="db_desg"><br>
Current CTC<br>
<input type="text" name="db_ctc"><br>
Upload your Resume<br>
<input type="file" name="attachment" size="40"><br>
Message<br>
<textarea name="cf_message"></textarea><br><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>
</body>
</html>
PHP 代码:文件名:Careers.php
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_dob = $_POST['db_name'];
$field_contact = $_POST['db_cntct'];
$field_board = $_POST['cf_board'];
$field_grad = $_POST['db_grad'];
$field_pgrad = $_POST['cf_pgrad'];
$field_emplyr = $_POST['db_emplyr'];
$field_doj = $_POST['cf_doj'];
$field_desg = $_POST['db_desg'];
$field_ctc = $_POST['db_ctc'];
$field_message = $_POST['cf_message'];
$mail_to = 'sachinrocksus@gmail.com';
$subject = 'Job Application from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Date of Birth: '.$field_dob."\n";
$body_message .= 'Contact Number: '.$field_contact."\n";
$body_message .= 'Class 12 Marks/CGPA/Percentage: '.$field_board."\n";
$body_message .= 'Graduation Marks/CGPA/Percentage: '.$field_grad."\n";
$body_message .= 'Post-Graduation Marks/CGPA/Percentage: '.$field_pgrad."\n";
$body_message .= 'Present Employer: '.$field_emplyr."\n";
$body_message .= 'Date of Joining: '.$field_doj."\n";
$body_message .= 'Designation: '.$field_desg."\n";
$body_message .= 'Current CTC: '.$field_ctc."\n";
$body_message .= 'Message: '.$field_message."\n";
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Your Job Application has been recieved. We will contact you shortly.');
window.location = 'Careers.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed');
window.location = 'Careers.html';
</script>
<?php
}
?>