PHP 联系表格未发送

发布于 2024-08-22 05:11:27 字数 2220 浏览 5 评论 0 原文

我的页面上有一个联系表单,可将​​表单的详细信息发送到电子邮件地址。您可以在这里查看它,www.wonder.ie

表单的 HTML 如下:

<form id="form" name="form27" class="wufoo  page" enctype="multipart/form-data" method="post" action="mailer.php">  
    <ul>
        <li id="foli1">
            <label class="op" id="title1" for="Field1">Name</label>
            <div><input id="Field1" name="name" type="text" class="op required" value="" maxlength="255" tabindex="1" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>  
        </li>

        <li id="foli2">
        <label class="op" id="title2" for="Field2">Email</label>
            <div><input id="Field2" name="email" type="text" class="op required email" value="" maxlength="255" tabindex="2" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>
        </li>

        <li id="foli3">
            <label class="op" id="title3" for="Field3">Inquiry</label>
            <div><textarea id="Field3" name="message" class="op required" rows="10" cols="50" tabindex="3" onkeyup="handleInput(this);" onchange="handleInput(this);"></textarea></div>
        </li>
        </ul>  
        <input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />         
</form>

对于我的 PHP 来说,它是这样的:

<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "Email from Wonder.ie";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

一切看起来都正确吗?我知道我的表单名称与 PHP 正确匹配,但我不明白为什么我没有收到您知道的电子邮件 - 仅供参考,网站上的 PHP 有一个真实的电子邮件地址,而不是 [电子邮件受保护]。一旦我点击提交按钮,我就会被带到 mailer.php,但我注意到回声“blarg!”所以我的猜测是电子邮件没有被发送。

谢谢你!

I have a contact form on a page that sends the details of the form to an email address. You can view it here, www.wonder.ie

The HTML for the form is the following:

<form id="form" name="form27" class="wufoo  page" enctype="multipart/form-data" method="post" action="mailer.php">  
    <ul>
        <li id="foli1">
            <label class="op" id="title1" for="Field1">Name</label>
            <div><input id="Field1" name="name" type="text" class="op required" value="" maxlength="255" tabindex="1" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>  
        </li>

        <li id="foli2">
        <label class="op" id="title2" for="Field2">Email</label>
            <div><input id="Field2" name="email" type="text" class="op required email" value="" maxlength="255" tabindex="2" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>
        </li>

        <li id="foli3">
            <label class="op" id="title3" for="Field3">Inquiry</label>
            <div><textarea id="Field3" name="message" class="op required" rows="10" cols="50" tabindex="3" onkeyup="handleInput(this);" onchange="handleInput(this);"></textarea></div>
        </li>
        </ul>  
        <input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />         
</form>

And for my PHP it is this:

<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "Email from Wonder.ie";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

Does everything look correct? I know I have the form names matched correctly with the PHP but I can't figure out why I'm not receiving the email you know - FYI the PHP on the site has a real email address, not [email protected]. Once I hit the submit button I am taken to mailer.php but I notice the echo "blarg!" so my guess is the email is not being sent.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

埋葬我深情 2024-08-29 05:11:27

你应该更改

if(isset($_POST['submit'])) {

if(isset($_POST['saveForm'])) {

You should change

if(isset($_POST['submit'])) {

to

if(isset($_POST['saveForm'])) {
ぽ尐不点ル 2024-08-29 05:11:27

尝试更改

if(isset($_POST['submit'])) {

if(isset($_POST['saveForm'])) {

这是因为 $_POST 查找表单输入的名称,而不是类型。

Try changing

if(isset($_POST['submit'])) {

to

if(isset($_POST['saveForm'])) {

This is because $_POST looks for the name of a form input, not the type.

甜妞爱困 2024-08-29 05:11:27

如果以上没有帮助,请尝试看看是否可以调试代码。

捕获 PHP mail() 错误并显示合理的用户错误消息

If nothing above helps, try and see if you can debug the code.

Catching PHP mail() errors and showing reasonable user error message

少女情怀诗 2024-08-29 05:11:27

在您的 PHP 代码中,您检查是否设置了 $_POST['submit'] ,但在您的 HTML 代码中,您为提交按钮指定了 saveForm 的名称,因此您应该更改希望

if(isset($_POST['submit'])) {

这对

if(isset($_POST['saveForm'])) {

您有帮助:)

In your PHP code you check if $_POST['submit'] is set, but in your HTML code you gave the submit button the name of saveForm so you should change the line

if(isset($_POST['submit'])) {

to

if(isset($_POST['saveForm'])) {

Hope this helped you :)

旧街凉风 2024-08-29 05:11:27

某些电子邮件服务器不会接受没有适当标头且您未提供标头的电子邮件。这就是我用的。

https://www.php.net/manual/en/function.mail。 php

$header = "From: ".$fromText."\r\n";
$header .= "Cc: ".$ccText."\n";
$header .= "Reply-To : ".$fromText."\r\n";
$header .= "Return-Path : ".$fromText."\r\n";
$header .= "X-Mailer: PHP\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);

Some email servers won't accept emails without appropriate headers and you haven't provided any. This is what I use.

https://www.php.net/manual/en/function.mail.php

$header = "From: ".$fromText."\r\n";
$header .= "Cc: ".$ccText."\n";
$header .= "Reply-To : ".$fromText."\r\n";
$header .= "Return-Path : ".$fromText."\r\n";
$header .= "X-Mailer: PHP\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
琴流音 2024-08-29 05:11:27

您正在使用

if(isset($_POST['submit'])) {

但是,您已将提交按钮名称另存为saveForm
所以,使用

if(isset($_POST['saveForm'])) {

you are using

if(isset($_POST['submit'])) {

but, you have save the submit button name assaveForm
So, use

if(isset($_POST['saveForm'])) {

笑看君怀她人 2024-08-29 05:11:27

你的问题是它的倾诉。
这肯定是该帖子没有到达您的手中

代码->

mail($to, $subject, $body);

并且提交的名称应更改为

'保存表单'

顺便说一下

:)..刚刚

mail($to, $subject, $body);

在您的 x.php 中尝试过,上传它并更改为正确的内容,主题和正文
如果已发送,则邮件功能正常。

 if(@mail($emailRecipient, $subject, $message, $headers))
    {
      echo "Mail Sent Successfully";
    }else{
      echo "Mail Not Sent";
    }

这也是我在 stackoverflow 中找到的一个很好的代码
检查邮件功能是否有效。

your problem is it's pour out blarg.
it's definitely the post does not reach your

code->

mail($to, $subject, $body);

and the name of the submit should be changed to

'saveForm'

by the way :)..

just tried

mail($to, $subject, $body);

in your x.php , upload it and chage to , subject and body to right things
and if it's sent then the mail function works okay.

 if(@mail($emailRecipient, $subject, $message, $headers))
    {
      echo "Mail Sent Successfully";
    }else{
      echo "Mail Not Sent";
    }

this is also a good code I have found in stackoverflow
to check if mail function works.

沫尐诺 2024-08-29 05:11:27

在你的 html 中

<input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />

,但在 php 文件中,当你检查 $_POST["submit"] 时,这是不正确的。

您需要将 if(isset($_POST['submit'])) 更改为 if(isset($_POST['saveForm']))

if (isset($_POST['提交']))if(isset($_POST))

In your html your have

<input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />

but in the php file when you check for $_POST["submit"], which is not right.

You need to change if(isset($_POST['submit'])) to if(isset($_POST['saveForm']))

or if(isset($_POST['submit'])) to if(isset($_POST))

同尘 2024-08-29 05:11:27

PHP 中 HTML 表单邮件发送指南 http://top-answers.net/webhost/web-托管.html

HTML form mail sending guide in PHP http://top-answers.net/webhost/web-hosting.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文