Я пытаюсь отправить прикрепленный файл из контактной формы. Я основываю свой код, используя пример phpMailer, но при этом никакое вложение не отправляется. Не уверен, что я делаю неправильно. Имя прилагаемого ввода - clientResume.PHP Mailer отправляет пустое приложение
<div id='contactForm' class='animated'>
<div id='formClose'>X</div>
<form id="form" action="employerForm.php" method="post" enctype="multipart/form-data">
<h1>Get Started For Free!</h1>
<label>Name</label>
<input class="formField" placeholder="Name" type="text" name="clientName" required>
<label>Email</label>
<input class="formField" placeholder="Email" type="email" name="clientEmail" required>
<label>Resume</label>
<input class="formField" placeholder="Resume" type="file" name="clientResume" required>
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<input id='formButton' type='button' value='Submit'>
</form>
</div>
var name = $('input[name="clientName"]').val(),
email = $('input[name="clientEmail"]').val(),
company = $('input[name="clientCompany"]').val(),
comment = $('input[name="clientComment"]').val(),
resume = $('input[name="clientResume"]').val(),
form = $(document).find("form"),
formData = form.serialize();
$.ajax({
type: 'POST',
url: form.attr('action'),
data: formData,
AccessControlAllowOrigin: '*';
});
<?php
require_once('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$name = $_POST['clientName'];
$email = $_POST['clientEmail'];
$attachment = tempnam(sys_get_temp_dir(), sha1($_FILES['clientResume']['tmp_name']));
$subject = "Resume Submission [$name]";
$message = "Name: $name " . "<br>Email: $email";
$mail->isSMTP();
$mail->Debugoutput = 'html';
$mail->Host = 'correlation-host.correlation-one.com';
$mail->Port = 25;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = false;
$mail->setFrom($email, $name);
$mail->addAddress('[email protected]', 'Michael Paccione');
$mail->Subject = 'PHPMailer SMTP test';
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['clientResume']['name']));
if (move_uploaded_file($_FILES['clientResume']['tmp_name'], $uploadfile)) {
$mail->addAttachment($uploadfile, 'resume');
}
$mail->msgHTML($message);
$mail->Send();
$mail->SmtpClose();
?>
Что это за функция возврата tempnam()? – Gopalakrishnan
Это из примера загрузки почтовой программы php на github. https://github.com/PHPMailer/PHPMailer/blob/master/examples/send_file_upload.phps –