-2
在我的網站上有一個查詢表單輸入一封電子郵件後無法發送電子郵件,並點擊提交獲取爲「無法發送郵件」。它正在重定向到另一個並顯示消息。需要對顯示在同一page.Here消息是代碼:在php中發送電子郵件不起作用
的index.php
<form action="contact.php" method="post" enctype="multipart/form-data">
<input type="email" size="30" placeholder=" Enter your Email and Get Notified..." name="email" id="email">
<a href="#"><button type="submit" class="btn span btn-4 btn-4a icon-arrow-right"><span></span></button></a>
<div id="response"></div>
</form>
contact.php:
<?php
$connection = mysql_connect("localhost", "mk_group", "12345") or die(mysql_error());
$db = mysql_select_db("group", $connection);
$email = $_POST['email'] ;
$sql2 = mysql_query("insert into contact_us(email) values ('$email')");
if ($sql2)
{
$to = "[email protected],[email protected]";
$subject = 'the subject';
$message = 'hello';
$retval = mail ($to,$subject,$message);
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>
強烈建議不要使用'mysql_ *'。使用'mysqli_ *'或'PDO' –
也容易受到sql注入 – Jakumi
@MrProPop我需要發送到不同的電子郵件ID – user6728960