Добавить вложение через PHPMailer
У меня есть следующий фрагмент кода PHPMailer. Проблема в том, что файл успешно загружен на сервер, но вложение не отправлено по почте. Код вложения кажется правильным, насколько мне известно. Пожалуйста, ознакомьтесь с кодом и дайте мне знать, где я ошибся.
форма
Title *
Title
Mr.
Ms.
Mrs.
First Name *
Last Name *
Email Address *
Telephone Number *
Details
Or upload a file (only word, excel or pdf)
send1.php
0)
{
echo "alert('Error: " . $_FILES["file"]["error"] ."')";
}
else
{
$d='upload/';
$de=$d . basename($_FILES['file']['name']);
move_uploaded_file($_FILES["file"]["tmp_name"], $de);
$fileName = $_FILES['file']['name'];
$filePath = $_FILES['file']['tmp_name'];
//add only if the file is an upload
}
}
else
{
echo "alert('Invalid file')";
}
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "hidden";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "hidden";
//Password to use for SMTP authentication
$mail->Password = "hidden";
//Set who the message is to be sent from
$mail->SetFrom($email_from, $first_name.' '.$last_name);
//Set an alternative reply-to address
//$mail->AddReplyTo('[email protected]','First Last');
//Set who the message is to be sent to
$mail->AddAddress('hidden', 'hidden');
//Set the subject line
$mail->Subject = 'Request for Profile Check up';
//Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
$mail->MsgHTML($email_message);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->AddAttachment($file);
$mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
//Send the message, check for errors
if(!$mail->Send()) {
echo "alert('Mailer Error: " . $mail->ErrorInfo."')";
} else {
echo "alert('Your request has been submitted. We will contact you soon.')";
Header('Location: main.php');
}
}
?>
РЕДАКТИРОВАТЬ Письмо успешно отправлено со всеми деталями. Просто вложение победилоотправить.
РЕДАКТИРОВАТЬ 2: решено Изменено$mail->MsgHTML
в$mail->Body
и это сработало!