< TextArea>不通过电子邮件发送 [英] <textarea> Not sending via email

查看:287
本文介绍了< TextArea>不通过电子邮件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为客户端创建一个简单的电子邮件表单,无法获取< textarea> 作为消息发送。我已经尝试了迄今为止发现的一切,没有任何正常工作...

这是我的代码:

I'm trying to create a simple email form for a client and cannot get the <textarea> to send as a message. I've tried everything I have found so far and nothing is working properly...
Here is my code:

<h4>Email Al</h4>
<table>
<form name="contactForm" id="contact" action="send_form_email.php" method="post">
    <tr>
    <td>
    <label>Name:</label>
    <input type="text" name="name">
    </td>
    <td>
    <label>Email Address:</label>
    <input type="email" name="email">
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <label>Website (if Available):</label>
    <input type="text" name="website">
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <label>Your Message:</label></br>
    <textarea for="" name="information" width="100%" rows="10" form="contactForm"></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <input type="submit" value="Send Message">
    </td>
    </tr>
</form>
</table>

这是index.php文件中的表单,下面是电子邮件send-email.php

That is the form in the index.php file, below is the email send-email.php

<?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  $website = $_POST['website'];
  $message = $_POST['information'];

    $email_from = 'myemail@gmail.com';

    $email_subject = $name . " has sent you a message!";

    $email_body = "You have received a new message from " . $name . " via your website!\n".
                            "Name:\n $name\n".
                            "Email:\n $email\n".
                            "Website:\n $website\n".
                            "Message:\n $message\n".



  $to = "clientemail@gmail.com";

  $headers = "From: $email_from \r\n";

  $headers .= "Reply-To: $visitor_email \r\n";

  mail($to,$email_subject,$email_body,$headers);


function IsInjected($str)
{
    $injections = array('(\n+)',
           '(\r+)',
           '(\t+)',
           '(%0A+)',
           '(%0D+)',
           '(%08+)',
           '(%09+)'
           );

    $inject = join('|', $injections);
    $inject = "/$inject/i";

    if(preg_match($inject,$str))
    {
      return true;
    }
    else
    {
      return false;
    }
}

if(IsInjected($visitor_email))
{
    echo "Bad email value!";
    exit;
}
?>
<?php
header("Location: /formsubmitted.php"); /* Redirect browser */
exit();
?>

如果有人有任何线索为什么这是故障,我也很想知道!这是我通常为wordpress开发的第一个消息/电子邮件php函数之一,所以我通常会为我的客户端安装一个插件。感谢高级的帮助!

If anyone has any clue why this is malfunctioning I would love to know as well! This is one of the first message/email php functions I've created myself as I usually develop for wordpress, so I would normally just install a plugin for my client. Thanks in advanced for the help!

推荐答案

这是因为这一行: (咨询我的脚注) / em>

"Message:\n $message\n".

您有一个点,而不是(关闭)分号;

You have a dot instead of a (closing) semi-colon ;

编辑:您需要删除 form =contactForm< textarea> 。测试时,它不会在邮件中显示,与它一起使用。

You need to remove form="contactForm" from <textarea>. Upon testing, it did not show in mail when used with it.

,错误报告将告诉您。

  • http://php.net/manual/en/function.error-reporting.php

存在:


注意:未定义的索引:信息(第8行)

Notice: Undefined index: information (line 8)


注意:未定义的变量:visitor_email(第26和55行)

Notice: Undefined variable: visitor_email (line 26 and 55)

在两者中:

$headers .= "Reply-To: $visitor_email \r\n";

if(IsInjected($visitor_email))

$ visitor_email 在您的代码中未定义。您应该为 $ visitor_email 的所有实例使用 $ email

$visitor_email is undefined in your code. You should have used $email instead for all instances of $visitor_email.

然后你有 for =,这在< textarea ...

for =是不明确的。

参考: https://developer.mozilla.org / en / docs / Web / HTML / Element / textarea

您还应使用条件!空)

  • http://php.net/manual/en/function.empty.php

脚注:

经过更多的测试,关于点我上面提到的,我必须说明如下:

After more intensive testing, and in regards to the dot that I mentioned above, I must state the following:

奇怪的是,PHP认为它是有效的语法,因为有一个半 - 在这里结束并包含在这里 $ to =clientemail@gmail.com;

Strangely enough, PHP sees it as being valid syntax, as there is a semi-colon in and included at the end here $to = "clientemail@gmail.com";

仍然会发送邮件,但是也包括在电子邮件中,这显然不包括在 $ email_body 变体中。

What that will do is still send mail, BUT also include that in the email, which is clearly not included in the $email_body variable body.

因此,我的答案的第一部分在一定程度上是正确的, form =contactForm是主要的罪魁祸首

Therefore, the first part of my answer was right to a certain extent, the form="contactForm" being the major culprit here.


  • 您可能要使用ID id =contactForm或者一个类 class =contactForm。两者都有效使用,并将其包含在您的邮件中。

  • You may have meant to use an ID id="contactForm" or a class class="contactForm". Both are valid to be used and will include it in your mail.

但是,您将无法使用 name =contactForm,因为您的< form> 保存该命名属性。

However, you won't be able to use name="contactForm" since your <form> holds that named attribute.


  • 名称 id 属性(意为是)唯一。

  • Both the name and id attributes are (meant to be) unique.

这篇关于&LT; TextArea&GT;不通过电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆