$(".feedback input.sent").click(function(e) {
e.preventDefault();
var name = $(".feedback textarea.name").val();
var mail = $(".feedback textarea.mail").val();
var phone = $("feedback textarea.phone").val();
// the file field probably has to be here somewhere as well?
var info = $(".feedback textarea.info").val();
if (name && mail && info) {
var data = {name: name, mail: mail, phone: phone, info: info};
// I guess I need to somehow get the file itself to this array to pass it to phpMailer?
$.post(baseUrl + "templates/feedback.php", data, function() {
$(".contact-form input, .contact-form textarea").val("");
console.log("great");
});
}
else {
console.log("not great");
}
});
Obviously I need to add multiple attachments, but I do not know how to pass them to the $mail->AddAttachment($target_path);
which is what I need help with.
I am using this to add multiple files.
My phpMailer works well until I add the AddAttachment() there, then it won't send an e-mail. I added a link for a picture there for example. It doesn't give me any errors as well, which is why I came here.
My primary need is still passing the what ever file(s) it is from the form to my feedback.php file, where the mailer does it's thing and attaching it/them all to the e-mail.
feedback.php file:
<?php
require_once "phpmailer.inc.php";
if ($_POST['name'] && $_POST['info']) {
$message = "";
$message .= "Name:\n" . $_POST['name'] . "\n\n";
$message .= "E-Mail:\n" . $_POST['mail'] . "\n\n";
$message .= "Phone:\n" . $_POST['phone'] . "\n\n";
$message .= "Message:\n" . $_POST['info'] . "\n\n";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "xxx.xxx.xxx";
$mail->Port = 25;
$mail->From = "xxx@xxx.xxx";
$mail->AddAddress("xxx@xxx.xxx");
foreach($_FILES as $key => $file){
$target_path = "uploads/";
$target_path = $target_path .basename($file['name']);
if(move_uploaded_file($file['tmp_name'], $target_path)) {
echo "the file ".basename($file['name'])." has been uploaded";
}
else {
echo "there was an error";
}
$mail->AddAttachment($target_path);
}
$mail->Subject = "Feedback";
$mail->Body = $message;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Error.';
echo 'Problem: ' . $mail->ErrorInfo;
} else {
echo 'Good';
}
}
?>
I am really not sure about the Attachment part there, I found it from here somewhere, but using it without the fancy loop doesn't work as well...