简体   繁体   English

无法使用PHP发送邮件

[英]Can’t send mail with PHP

I want to be able to send what a user enters in a textfield to my email by PHP, but when I click the “submit” button the page refreshes, the textfield clears, and no email is sent to my email address. 我希望能够通过PHP将用户在文本字段中输入的内容发送到我的电子邮件中,但是当我单击“提交”按钮时,页面将刷新,文本字段将清除,并且没有电子邮件发送到我的电子邮件地址。

Here is my PHP: 这是我的PHP:

<?php
$mail = $_POST['mail'];
$formcontent = "Email: $mail";
$recipient = "angrybullet2.webhosting@gmail.com";
$subject = "Mail that uploaded picture";
$mailheader = "From: my website";

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo 'OK ! Your mail address has been successfully added to your photo !<br>We will contact you later :)';
?>

Here is my HTML: 这是我的HTML:

<html>
<body bgcolor="lightpink">
  <div align="center">
    <font face="helvetica" size="5px" color="#009933">
      Your photos has been successfully uploaded !<br>Enter your email address to tell you how to win the $50 000 !
    </font>
    <form name="form" id="login" method="POST" action="up_ok_send_mail.php">
      <input type="text" name="mail" id="mail" size="70" placeholder="Enter your email address here">
      <input type="submit" name="submit" id="submit" value="submit">
    </form>
</body>
  </div>
</html>

I don't know what's happening. 我不知道发生了什么 I tried to web host this HTML with this PHP in a directory apart from the rest of my website's parts (including the print_r function that Mohan suggested me to add ). 我尝试使用此PHP将HTML托管在网站的其余部分之外的目录中(包括Mohan建议我添加print_r函数)。 And everything is great, but when this HTML is linked to a page that has to be before it, the whole thing does not work. 一切都很好,但是当此HTML链接到必须在其之前的页面时,整个过程将无法正常工作。 When submitting the email the page refreshes and no email is sent to my email address. 提交电子邮件时,页面刷新,并且没有电子邮件发送到我的电子邮件地址。


Okay. 好的。 It worked. 有效。 I managed to fix my problem by making the email submission field in the same HTML file that it was linked to. 我设法通过将电子邮件提交字段放在链接到的同一HTML文件中来解决问题。 I mean there is no more links to this page. 我的意思是,该页面没有更多链接。 Everything is on the same HTML now. 现在,所有内容都使用相同的HTML。

表单未提交,或者如果您在本地主机工作,则没有smtp协议发送邮件,请检查表单是否正在提交至up_ok_send_mail.php页面

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

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