我想通過電子郵件從網頁收集的字符串通過PHP,但我沒有任何運氣。很多關於製作jQuery表單的信息,但找不到任何只是通過電子郵件發送字符串的信息。通過電子郵件收集使用jQuery的字符串
這裏是我到目前爲止有:
$('.questionFive').click(function(){
$.post("mail.php", preSubmit())
});
// this works well, and returns the string as desired.
function preSubmit(){
var optionTexts = [];
$("section").each(function(){
var h2 = $(this).find("h2").text();
optionTexts.push(h2);
$("ol li", this).each(function() { optionTexts.push($(this).text()) });
optionTexts.push("\n");
});
var optionString = optionTexts.toString();
var splitText = optionString.split(",");
alert(splitText);
return splitText;
}
// mail.php file
<?php
if (isset($_POST['mailstring']) {
$mail = $_POST['mailstring'];
mail('[email protected]', 'My Subject', $mail);
}
?>
你驗證形式獨立工作從jQuery - 我會先排除這種可能性。用你的mail.php文件手動提交表單 - 這可以告訴我們,服務器配置正確的電子郵件和一切與您的HTML和PHP提交腳本。我們也可以請看看html嗎? ty – Joe
同樣值得注意的是,在幾行代碼中會丟失幾個分號,這會導致問題。特別是在preSubmit函數中使用alert的行:alert(splitText)和您的optionText陣列推送調用 – Joe
JavaScript中的分號是一個非常好的主意,但它們不是必需的。 –