当我点击表单上的提交时,表单会将我重定向到" process.php"并且电子邮件没有发送,但是当我点击刷新时,它会发送垃圾邮件。如何让PHP不要将我重定向到其他页面并根据表单中的内容发送电子邮件。
这是我的代码
PHP
$toemail = 'email@gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if(mail($toemail, 'Subject', $message, 'From: ' . $email)) {
echo 'Your email was sent successfully.';
} else {
echo 'There was a problem sending your email.';
}
HTML
<h2>Leave a message</h2>
<div class="sepContainer"></div>
<form action="process.php" method="post" id="contact_form">
<div class="name">
<label for="name">Your Name:</label>
<p> Please enter your full name</p>
<input id=name name=name type=text placeholder="e.g. Mr. John Smith" required />
</div>
<div class="email">
<label for="email">Your Email:</label>
<p> Please enter your email address</p>
<input id=email name=email type=email placeholder="example@domain.com" required />
</div>
<div class="message">
<label for="message">Your Message:</label>
<p> Please enter your question</p>
<textarea id=message name=message rows=6 cols=10 required></textarea>
</div>
<div id="loader">
<input type="submit" value="Submit" />
</div>
</form>
它托管在Unix服务器上。尽量不要苛刻我现在只学习PHP 2天了。
答案 0 :(得分:0)
<?php
$name = $_POST ['name'];
$request = $_POST['request'];
$to = "(email goes here)";
$subject = "Website Quote";
$body = "This is an automated message. Please do not reply to this emai. \n\n $request";
mail ($to,$subject,$body);
echo "Message Sent. <a href='index.html'>Click here to return to the site.</a>"
?>
以下是发送电子邮件的真正基本PHP代码,这就是您尝试做的事情。
HTML -
<form action="send.php" method="POST">
Name: <br> <input type="text" name="name"><br>
Request <br> <textarea name="request"></textarea><br><br>
<input type="submit" name="submit" value="Send">
</form>
希望这可以解决一些问题,如果我接近这个问题,请以不同方式解释,谢谢,祝你有个美好的一天!