<?php
if ($_POST['name'] && $_POST['info']) {
$message = "";
$message .= "Nimi:\n" . $_POST['name'] . "\n\n";
$message .= "E-mail:\n" . $_POST['mail'] . "\n\n";
$message .= "Phone:\n" . $_POST['phone'] . "\n\n";
$message .= "File:\n" . $_POST['file'] . "\n\n"; // probably wrong
$message .= "Message:\n" . $_POST['info'] . "\n\n";
mail("me@me.me", "blablabla (example.com)", $message, "From: example.com <me@me.me>");
}
我正在使用 jquery-ajax 获取所有其他值(从 textareas 获取 val() 并将它们发布到 process.php 文件),但是如何传递文件并在邮件函数中使用它?
我看了一些插件,但我更喜欢在我已经拥有的代码中添加一些东西,它不会那么难......
$("input.submit").click(function(e) {
e.preventDefault();
var name = $(".feedback textarea.name").val();
var mail = $(".feedback textarea.mail").val();
var phone = $("feedback textarea.phone").val();
var file = $("feedback input.file").val(); //probably wrong
var info = $(".feedback textarea.info").val();
if (name && mail && info) {
var data = {name: name, mail: mail, phone: phone, file: file, info: info};
$.post("process.php", data, function() {
$("textarea, input").val("");
alert("thank you for submitting");
});
}
else {
alert("something is missing");
}
});