因此,我正在製作一個電子郵件表單,並使用AJAX鏈接到使用PHPMailer發送電子郵件的外部PHP文件。所以我在PHP的頂部驗證碼:表單字段值沒有被傳遞給PHP文件
if(count($_POST) > 0){
$message=
'Full Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
Message: '.$_POST['textarea'].'<br />
Current Website: '.$_POST['website'].'<br />
Business Name: '.$_POST['business'].'<br />
';
,並
- 在本地主機使用WAMP,這將很好地工作,並會發送電子郵件與各自領域
- 在現場版本,電子郵件不通過在PHP文件中的
if(count($_POST) > 0)
如果if語句被刪除,它確實發送電子郵件,我收到它,但電子郵件只有「全名:」和「電子郵件:」等填充空白和n o從HTML表單輸入的值。這裏是AJAX代碼:
var ajax = { isSubmiting: false, send: function() { if(ajax.isSubmiting == false) { ajax.isSubmiting = true; var name = $("input[name=name]").val(); var email = $("input[name=email]").val(); var textarea = $("textarea").val(); var business = $("input[name=business]").val(); var website = $("input[name=website]").val(); ajax.SetText("Sending..."); $.post("sendmail.php", { name: name, email: email, textarea: textarea, business: business, website: website }, function(data) { if (data.trim() == "true") { ajax.SetText("Sent!"); console.log(data); $.get("sent.html", function(sentData){ $("#content").html(sentData); }); } else { ajax.SetText("Send mail"); console.log(data); $.get("unsent.html", function(sentData){ $("#content").html(sentData); }); } ajax.isSubmiting = false; }); } else alert("You can only send one email at a time!"); }, SetText: function(text) { $("input[type=button]").val(text); } }
,這是形式的HTML標記:
<form name="contact-form" method="post" id="contact-form">
<h3> We want to hear from you! Tell us about your business and/or project and what you need and we'll get back to you as soon as possible! </h3>
<div class="form-group">
<label for="name">Your Name:</label>
<input type="text" name="name" class="form-control" placeholder="Your Name" required/>
</div>
<div class="form-group">
<label for="email">Your Email:</label>
<input type="email" name="email" class="form-control" placeholder="Your Name" required/>
</div>
<div class="form-group">
<label for="web">Current Website (if available):</label>
<input type="text" name="website" class="form-control" placeholder="Current Website (if available)"/>
</div>
<div class="form-group">
<label for="web">Business Name (if available):</label>
<input type="text" name="business" class="form-control" placeholder="Business Name (if available)"/>
</div>
<div class="form-group">
<label for="comment">Message:</label>
<textarea id="textarea" rows="5" class="form-control" name="textarea" placeholder="Message"></textarea>
</div>
<div class="row" align="center" id="button-row2">
<input type="button" value="Submit" onClick="ajax.send()" class="btn">
</div>
</form>
任何想法,爲什麼這可能是這樣嗎?
你能否證實,在這兩種情況下(測試和生活)你的AJAX代碼正在運行,而不是形式開始提交的HTML表單到同一頁面的URL它的位置? – fvgs
另外,你可以確認變量'名稱,電子郵件,textarea等'是否填充之前,在實時環境中發送? – fvgs
@fvgs我確定AJAX正在運行,因爲在$ .post之後,它表示數據== true,它將以其他方式返回。我猜,這意味着它首先經歷了它。而且我爲每個變量輸入了值,但是如何確認? –