在我的php页面中,我从表单发送邮件。它发送良好但不发送附件。这是代码......
<form action="career.php" method="POST" class="form-horizontal companyInquiry">
<div class="alert alert-danger" style="margin: 10px; display:none;" id="errorLabel"></div>
<?php
if(isset($_SESSION['error'])) {
echo "<div class='alert alert-danger' style='margin: 10px;' id='errorLabel'>";
foreach ($_SESSION['error'] as $err) echo "<p><b>$err</b></p>";
echo "</div>";
unset($_SESSION['error']);
}
if(isset($_SESSION['message'])) {
echo "<div class='alert alert-success' style='margin: 10px;' id='errorLabel'><p><b>".$_SESSION['message']."</b></p></div>";
unset($_SESSION['message']);
}
?>
<p style="padding: 0px 10px; text-align:center; font-weight:bold; color:#6E0C0B; font-size:16px;">
We Have Current Openings For.
</p>
<p style="padding: 0px 10px; text-align:center; font-weight:bold; ">
Experienced Graphics designer(2 to 3 year).
</p>
<p style="padding: 0px 10px; text-align:center; font-weight:bold; ">
Experienced PHP developer(2 to 3 year).
</p>
<p style="padding: 0px 10px; text-align:center; font-weight:bold; ">
Interested Candidate, Please fill below form with fresh resume.
</p>
<div class="form-group">
<label for="fullName" class="col-sm-2 control-label">Full Name</label>
<div class="col-sm-9">
<input type="text" name="fullName" id="fullName" class="form-control" placeholder="Enter Your Full Name" value="<?php if(isset($_SESSION['values'])) echo $_SESSION['values']['fullName'];?>" />
</div>
</div>
<div class="form-group">
<label for="userEmail" class="col-sm-2 control-label">Email</label>
<div class="col-sm-9">
<input type="text" name="userEmail" id="userEmail" class="form-control" placeholder="Enter Your Email" value="<?php if(isset($_SESSION['values'])) echo $_SESSION['values']['userEmail'];?>" />
</div>
</div>
<div class="form-group">
<label for="userContact" class="col-sm-2 control-label">Contact No</label>
<div class="col-sm-9">
<input type="text" name="userContact" id="userContact" class="form-control" placeholder="Enter Your Contact Number" value="<?php if(isset($_SESSION['values'])) echo $_SESSION['values']['userContact'];?>" />
</div>
</div>
<div class="form-group">
<label for="app_for" class="col-sm-2 control-label">Applied For</label>
<div class="col-sm-9">
<select name="app_for" id="app_for">
<option value="Graphics designer">Graphics designer</option>
<option value="PHP developer">PHP developer</option>
</select>
</div>
</div>
<div class="form-group">
<label for="you" class="col-sm-2 control-label">About You</label>
<div class="col-sm-9">
<textarea name="you" id="you" class="form-control" placeholder="Enter About You" style="border-radius:0"></textarea>
</div>
</div>
<div class="form-group">
<label for="cv" class="col-sm-2 control-label">Your CV</label>
<div class="col-sm-9">
<input type="file" name="cv" id="cv">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-9">
<p style="text-align:left;">
Only .xls,.xlsx,.pdf and .PDF extentions are allowed.
</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" name="send">Send</button>
</div>
</div>
<input type="hidden" name="company" value="<?php echo $_GET['com_id']; ?>" />
</form>
和我的career.php文件是。
<?php include_once("../../init.php");
date_default_timezone_set('Asia/Calcutta');
if($_SERVER['REQUEST_METHOD'] === 'POST') {
require_once(CONNECT);
require_once('../../public/includes/mailer/config/class.phpmailer.php');
$inc = -1;
if($_POST['fullName'] == '') {
$inc++;$_SESSION['error'][$inc] = "FULL NAME IS REQUIRED";
}
if($_POST['userEmail'] == '') {
$inc++;$_SESSION['error'][$inc] = "EMAIL IS REQUIRED";
}
if($_POST['userContact'] == '') {
$inc++;$_SESSION['error'][$inc] = "CONTACT NO IS REQUIRED";
}
if($_POST['userEmail'] != '' && $_POST['userEmail'] != null) {
if(!filter_var($_POST['userEmail'], FILTER_VALIDATE_EMAIL)) {
$inc++;$_SESSION['error'][$inc] = "INVALID EMAIL";
}
}
function inputs() {
$_SESSION['values']['fullName'] = $_POST['fullName'];
$_SESSION['values']['userEmail'] = $_POST['userEmail'];
$_SESSION['values']['userContact'] = $_POST['userContact'];
$_SESSION['values']['userMessage'] = $_POST['userMessage'];
header("location:".SLASHES."career/");
}
if($inc > -1) inputs();
else {
$date = date('Y-m-d H:i:s');
$mailBody =
"message";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'grimlock.secure-dns.net';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('jesadiyadivyesh@gmail.com', 'test');
$mail->addReplyTo('jesadiyadivyesh@gmail.com', 'test');
$mail->addAddress('jesadiyadivyesh@gmail.com', 'test');
if($_FILES["cv"]["name"]) $mail->AddAttachment($_FILES["cv"]["tmp_name"],$_FILES["cv"]["name"]);
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = "test";
$mail->Body = $mailBody;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
$_SESSION['error'][0] = "error in sending your data";
}
else{
$_SESSION['message'] = "your data send successfully";
}
header("location:".SLASHES."career/");
}
} else header("location:".SLASHES."career/");
&GT;
答案 0 :(得分:3)
您没有设置附件标头(enctype)。 添加到表单标记:
enctype="multipart/form-data"
应该是这样的:
<form action="career.php" method="POST" enctype="multipart/form-data" class="form-horizontal companyInquiry">