0
我做了一個HTML表單寬度AJAX:AJAX接觸形式不發送POST數據到PHP
function confirmSendMail() {
$(".send_contact").click(function(event){
event.preventDefault();
var nome = $("#inputName").val();
var email = $("#inputEmail").val();
var telefono = $("#inputTelefono").val();
var messaggio = $("#message").val();
$.ajax({
type: "POST",
url: "send.php",
data: "nome=" + nome + "&email=" + email + "&telefono=" + telefono + "&messaggio=" + messaggio,
success: function(msg) {
alert('messaggio inviato!')
},
error: function() {
alert("Si e' verificato un errore imprevisto...");
}
});
return false;
});
}
警報確認我的郵件被髮送出去,PHP引擎發送電子郵件...但它是空的,因爲POST不發送數據到PHP:
<?php
require 'PHPMailer-master/class.phpmailer.php';
$mail = new PHPMailer;
$nome = $_POST['inputName'];
$email = $_POST['inputEmail'];
$telefono = $_POST['inputTelefono'];
$messaggio = $_POST['message'];
$mail->From = $email;
$mail->FromName = $email;
$mail->AddAddress('[email protected]'); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
/* $mail->AddAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->AddAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name */
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'email dal form acfmavvocati.it';
$mail->Body = 'nome: ' . $nome . '<br /><br />email: ' . $email . '<br /><br />telefono: ' . $telefono . '<br /><br />messaggio: ' . $messaggio;
/* $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; */
if($mail->Send()) {
echo "works";
exit;
} else {
echo "doesn't work";
exit;
}
?>
我嘗試了許多解決方案,它帶給我瘋了。
在此先感謝您的幫助。
你是對的!正如我通常在表單中使用「行動」一樣,我並不擅長ajax發佈數據。非常感謝! – mimelaine 2015-03-08 21:34:14