2 回答

TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個(gè)贊
參見(jiàn)郵件功能文檔
有 3 個(gè)必需參數(shù):電子郵件目的地(收件人)、主題和消息,另外兩個(gè)選項(xiàng)是:標(biāo)頭和參數(shù)。
您的代碼不尊重這一點(diǎn),因?yàn)槟鄙偬砑又黝}作為參數(shù)。你會(huì)得到 ?mailsent 因?yàn)槟闶褂?header("Location: index.html?mailsent") 而不進(jìn)行任何測(cè)試電子郵件是否發(fā)送成功。
我建議你用這個(gè)替換你的 php 代碼的最后兩行
$subject = "some subject"; // you can replace it with $subject = $_POST["subject"]
$result = mail($mailTo, $subject , $txt,$headers);
if ($result){
? // mail send successfully
? ?header("Location: index.html?mailsent");
} else {
?// error
}
您可以使用 error_get_last() 函數(shù)獲取錯(cuò)誤消息。
$subject = "some subject"; // you can replace it with $subject = $_POST["subject"]
$result = mail($mailTo, $subject , $txt,$headers);
if ($result){
? // mail send successfully
? ?header("Location: index.html?mailsent");
} else {
?print_r(error_get_last());
}

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
您缺少表單操作,因此 PHP 不知道如何處理您的變量數(shù)據(jù)。嘗試添加method="post"內(nèi)部<form>標(biāo)簽。像這樣
<div class="contact_form">
<form action="/action_page.php" method="post">
<input type="text" id="name" name="name" placeholder="Name*">
<input class="contact_even" type="text" id="email" name="email" placeholder="Email id*">
<input type="text" id="phone" name="phone" placeholder="Phone No.">
<input class="contact_even" type="text" id="city" name="city" placeholder="City">
<textarea id="subject" name="subject" placeholder="How Can We Help You?"></textarea>
<input type="submit" value="Submit">
</form>
</div>
并且。如果您將計(jì)算機(jī)用作本地主機(jī)(使用 xampp 、 wamp 或沒(méi)有托管服務(wù)的東西),則必須對(duì)配置文件進(jìn)行一些更改。
也嘗試一下修改后的 php 代碼
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$message = $_POST['message'];
$title = "replace this";
$mailTo = 'support@udichi.in';
$txt = $name.'('.$phone.') from '.$city.' says:\n\n'.$message;
$headers = 'From: '.$mailFrom . PHP_EOL .'Reply-To:' .$mailFrom . PHP_EOL . 'X-Mailer: PHP/' . phpversion();
mail($mailTo,$title,$txt,$headers);
header("Location: index.html?mailsent");
}
?>
- 2 回答
- 0 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)