php邮件功能仅适用于本地服务器,不适用于远程服务器
正如标题一样,我在 HTML 中创建了一个简单的表单,
您可以在 http://thee-l 中看到它.comuv.com/send.php 这会向我发送一封电子邮件,其中指定了主题和正文我在 Apache 的本地主机上运行此电子邮件,不到一分钟就进入了我的收件箱,然后我将其上传到 我有一个 gmail地址,
所以为了方便起见,我使用 smtp2go 制作了一个外发 smtp 服务器,这是我的第一封 php 发送的电子邮件,我真的很高兴,并立即将其放在远程服务器,我们在这里,
我正在使用 000webhost
这是我的代码
<?php
if ($_POST['submit']){
ini_set("SMTP", "smtp2go.com");
ini_set("smtp_port", 2525);
$to = "[email protected]";
$subj = $_POST['topic'];
$body = $_POST['message'];
$header = "From: [email protected]";
if (mail($to, $subj, $body, $header))
{
echo "Message sent successfully";
}
else
{
echo "Message sent unsuccessfully";
}
}
else
{
echo "<html>
<form method=\"post\" action=\"send.php\">
Topic: <br/><input type=\"text\" name=\"topic\"/><br/>
Message: <br/><textarea name=\"message\"></textarea><br/>
<input type=\"submit\" value=\"Send\" name=\"submit\"/>
</form>
</html>";
}
?>
just as the title I created a simple form in HTML
you can see it at http://thee-l.comuv.com/send.php this sends an email to me with the subject and body text specified I run this on localhost from Apache and I get in my inbox in less than a minute but I then upload it to the remote server the site and it does not email me at all
I have a gmail address so to make it easy I made an outgoing smtp server with smtp2go this was my first php-sent email, I was really happy and right away put it on the remote server and here we are
I am using 000webhost
here is my code
<?php
if ($_POST['submit']){
ini_set("SMTP", "smtp2go.com");
ini_set("smtp_port", 2525);
$to = "[email protected]";
$subj = $_POST['topic'];
$body = $_POST['message'];
$header = "From: [email protected]";
if (mail($to, $subj, $body, $header))
{
echo "Message sent successfully";
}
else
{
echo "Message sent unsuccessfully";
}
}
else
{
echo "<html>
<form method=\"post\" action=\"send.php\">
Topic: <br/><input type=\"text\" name=\"topic\"/><br/>
Message: <br/><textarea name=\"message\"></textarea><br/>
<input type=\"submit\" value=\"Send\" name=\"submit\"/>
</form>
</html>";
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试点击您的链接,但显然您的网站正在接受审查(可能是因为您的测试导致邮寄过多/涉嫌垃圾邮件?)。即使这样,链接到
.php
页面也不会向我们显示代码,因为服务器将执行它并将结果发送到浏览器。最好将代码复制/粘贴到问题中。另外,正如@Computerish 所说,您可能刚刚遇到了主机的限制。您今天运行了多少次
mail()
代码?I tried clicking on your link, but apparently your website is under review (possibly for mailing too much/suspected of spamming because of your testing?). Even then, linking to a
.php
page won't show us the code, since the server will execute it and send just the result to the browser. It's better if you copy/paste your code into the question.Also, as @Computerish said, you may have just run into a limit on your host. How many times have you run your
mail()
code today?检查您的网络托管公司有关外发邮件的政策。可能有每日限制、完全禁止,或者可能是您必须要求的额外服务。几乎所有托管公司都会采取一些措施来限制 send() 函数的使用,以防止垃圾邮件发送者利用其服务器。
Check your web hosting company's policies about outgoing mail. There may be a daily limit, a outright ban on it, or it may be an extra service you have to ask for. Almost all hosting companies do something to limit the use of the send() function to prevent spammers from taking advantage of their servers.