![](/img/trans.png)
[英]issues/errors with from php form for sending email via local host Xampp using php-mailer library
[英]Issues sending email using my php form
我正在嘗試使用 VB.NET 2015 為我的網站設置一個簡單的“聯系我”表單。但我無法接收任何電子郵件。 這是我的文件:
PHP:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
//if "email" variable is filled out, send email
$email = htmlspecialchars($_POST["email"], ENT_QUOTES);
$subject = htmlspecialchars($_POST["subject"], ENT_QUOTES);
$comment = htmlspecialchars($_POST["comment"], ENT_QUOTES);
$comment = str_replace("\n.", "\n..", $comment);//message can't have \n.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: " . $email . "\r\n";
if(mail("foo@test.com ", $subject, $comment, $headers)){
//no error
exit;
}
echo "Error sending mail";
?>
打字稿:
module OnlinePortfolio {
export class ContactMe {
public static Email() {
$.ajax({
url: "SendMail.php",
type: "POST",
data: {
"subject": $("#subject").text(), "email": $("#email").text(), "message": $("#comment").text()
},
success: function (data, status) {
if (data === "") {
alert("Message sent successfully");
}
else {
alert("There was an issue with sending your message");
}
},
error: function (xhr, status, errorDescription) {
console.error('Something happened while sending the request: ' + status + ' - ' + errorDescription);
}
});
}
}
}
HTML
<html>
<form>
Email: <input id="email" type="text" /><br />
Subject: <input id="subject" type="text" /><br />
Message:<br />
<textarea id="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" onclick="OnlinePortfolio.ContactMe.Email()">
</form>
<html>
上面提供的電子郵件僅用於此帖子。 我對 php 相當陌生,但根據我所做的一些研究,這應該有效。 單擊提交按鈕時,我沒有收到任何錯誤。 我還打開了調試控制台,也沒有出現錯誤。 有人可以幫我理解為什么我沒有收到電子郵件嗎?
提前謝謝了!
請使用本地的 PHPMailer( https://github.com/PHPMailer/PHPMailer ))
看起來您正在使用 PHP 內置郵件功能。 不幸的是,它不適用於本地主機。 您需要從遠程服務器運行它才能使其工作。 如果您想從本地主機運行它,請使用第三方庫,例如 phpmailer。
1:localhost不能用mail()發送郵件,先上傳到服務器。 如果您必須在 localhost 中使用,請使用 phpmailer ( https://github.com/PHPMailer/PHPMailer ) 2:您未設置操作! 在真正的 html 腳本中設置它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.