简体   繁体   English

php重定向页面而不发送电子邮件

[英]php redirecting page and not sending email

When a I hit submit on my form, the form redirect's me to "process.php" and the email doesn't send, but when I hit refresh it sends the email with garbage in it. 当我在表单上点击提交时,表单重定向我的“process.php”并且电子邮件没有发送,但是当我点击刷新时,它会发送垃圾邮件。 How can I get PHP not to redirect me to a different page and send the email based on what's in the form. 如何让PHP不要将我重定向到另一个页面并根据表单中的内容发送电子邮件。

Here's my code 这是我的代码

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 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>

It's hosted on a Unix server. 它托管在Unix服务器上。 Try not to be to harsh I've only been learning PHP for 2 days now. 尽量不要苛刻我现在只学习PHP 2天了。

   <?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>"
 ?>

Here is REALLY basic PHP code to send an email, which is what it seems like you're attempting to do. 这是真正发送电子邮件的基本PHP代码,这就是您尝试做的事情。

HTML - 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>

Hopefully this clears something up, if I approached this incorrectly please explain it differently, thanks, have a great day! 希望这能清除一些东西,如果我接近这个错误,请以不同的方式解释,谢谢,祝你有美好的一天!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM