我創建了一個表單和PHP發送表單詳細信息到我的電子郵件。但通過本地主機運行通過wampserver的網頁時,它會顯示一個錯誤「警告:)郵件(:無法連接在本地主機"端口" 25至郵件服務器,驗證您的" SMTP "和" SMTP_PORT "設置在php.ini或使用在第22行的C:\ wamp \ www \ My \ web \ PHP \ ContactUs.php中創建ini_set()。我找不到在哪裏線22發送表單詳細信息到電子郵件
<div class="container">
<form name="htmlform" method="POST" action="../PHP/ContactUs.php">
<label for="name">Name</label>
<input type="text" id="name" name="name" placeholder="Your Name">
<label for="email">Email Address</label>
<input type="text" id="email" name="email" placeholder="Your Email Address">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="Your Phone Number">
<label for="Message">Message</label>
<textarea id="message" name="message" placeholder="Write You Something" style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "[email protected]";
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message = $_REQUEST['message'];
//send email
mail($admin_email, "$name", "$phone", "$message", "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<?php
}
?>
而不是使用'$ _REQUEST'(這將既$ _ POST和$ _GET方法的工作),這將是更好地使用$ _POST。該錯誤表明您正在嘗試在您的開發系統上執行此操作,並且沒有運行郵件服務器 – RamRaider
@RamRaider如何設置郵件服務器? –
這是一個相當廣泛的主題,你不得不問在你的開發系統上設置你自己的郵件服務器是否值得花費時間和精力,當PHP腳本將在晚些時候在因特網上託管?我會在php代碼中添加一些邏輯來檢查你是否在'localhost'上運行,如果是的話不發送郵件。另外,嘗試谷歌搜索''免費郵件服務器的Windows「'或看看https://stackoverflow.com/questions/16830673/wamp-send-mail-using-smtp-localhost〜那裏有很多解決方案 – RamRaider