发送邮件的表格不发送

发布于 2024-11-07 00:33:39 字数 1868 浏览 0 评论 0原文

我有一个“告诉朋友”弹出电子邮件表单,允许用户使用他们输入的电子邮件地址共享我的页面。它弹出得很好,但我无法获取发送电子邮件的表格。

html:

<div id="tellfriend">
      <a href="#close">Close</a>

      <form id='tellafriend_form' method="post" action="#sendMessage" name="tellafriend_form">

        <label for="name">Your Name:</label>
        <input type="text" id="name" name="name" />

        <label for="to">Friend's email:</label> 
        <input type="text" id="to" name="to" /> 

        <label for="subject">Subject:</label>
        <input type="text" id="subject" name="subject" /> 

        <label for="message">Message:</label> 
        <textarea id="message" name="message"></textarea>
        <input type="submit" name="submit" value="Submit">

      </form>

</div><!-- #tellfriend -->

处理“弹出窗口”的 javascript:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script> 
<script>
$(function() {
    $('#tellfriend').hide();
    $('#sendMessage').click(function(e) {
        $("#tellfriend").fadeToggle('fast');
    });

});
</script>

应该发送邮件的 php:

<?
if (isset($_POST['Submit'])) {
// This will check to see if the form has been submitted
$senders_name = $_POST['name'];
// The person who is submitting the form
$recipient_friend = $_POST['to'];
// The forms recipient
$subject = $_POST['subject'];
// The subject line
$message = $_POST['message'];
// The message being sent
mail($recipient_friend, "From $senders_name", $subject, $message);

if (isset($_POST['your_email'])) {
echo "<br>Your friend has been contacted <br><br>Thank you $senders_name";
}}
?>

免责声明:PHP 新手,希望学习。谢谢!

I have a "tell a friend" pop up email form that allows users to share my page with an email address that they enter. It pops up fine, but I can't get the form to send the email.

html:

<div id="tellfriend">
      <a href="#close">Close</a>

      <form id='tellafriend_form' method="post" action="#sendMessage" name="tellafriend_form">

        <label for="name">Your Name:</label>
        <input type="text" id="name" name="name" />

        <label for="to">Friend's email:</label> 
        <input type="text" id="to" name="to" /> 

        <label for="subject">Subject:</label>
        <input type="text" id="subject" name="subject" /> 

        <label for="message">Message:</label> 
        <textarea id="message" name="message"></textarea>
        <input type="submit" name="submit" value="Submit">

      </form>

</div><!-- #tellfriend -->

javascript that handles the "pop up":

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script> 
<script>
$(function() {
    $('#tellfriend').hide();
    $('#sendMessage').click(function(e) {
        $("#tellfriend").fadeToggle('fast');
    });

});
</script>

php that's supposed to send the mail:

<?
if (isset($_POST['Submit'])) {
// This will check to see if the form has been submitted
$senders_name = $_POST['name'];
// The person who is submitting the form
$recipient_friend = $_POST['to'];
// The forms recipient
$subject = $_POST['subject'];
// The subject line
$message = $_POST['message'];
// The message being sent
mail($recipient_friend, "From $senders_name", $subject, $message);

if (isset($_POST['your_email'])) {
echo "<br>Your friend has been contacted <br><br>Thank you $senders_name";
}}
?>

Disclaimer: PHP newbie, hoping to learn. Thanks!

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

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

发布评论

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

评论(3

万人眼中万个我 2024-11-14 00:33:39

您的邮件功能中的参数顺序不正确。请参阅 this

应该

mail($recipient_friend, $subject, $message);

如果您想使用标头,那么

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";    
$headers .= 'To: '.$recipient_friend.' <'.$recipient_friend.'>' . "\r\n";    
$headers .= 'From: '.$sender.' <'.$senderEM.'>' . "\r\n";    

这样做然后像这样调用邮件

mail($recipient_friend, $subject, $message, $headers);

The order of your parameters in mail function is not correct. see this

it should be

mail($recipient_friend, $subject, $message);

if you want to use headers then do this

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";    
$headers .= 'To: '.$recipient_friend.' <'.$recipient_friend.'>' . "\r\n";    
$headers .= 'From: '.$sender.' <'.$senderEM.'>' . "\r\n";    

Then call mail like this

mail($recipient_friend, $subject, $message, $headers);
行雁书 2024-11-14 00:33:39

您的 PHP 代码中有一个错误:

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

应该是:

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

带有小写“s”。

事实上,您提交按钮的名称是“提交”,但值是“提交”。
您最终可以这样做:

if (isset($_POST['submit']) &&  $_POST['submit'] == 'Submit') {

并且您的邮件参数不正确,就像 boug 所说的那样。

You have one error in your PHP code:

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

should be:

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

with a lowercase "s".

Indeed the name of you submit button is "submit" but the value is "Submit".
You could eventually do that:

if (isset($_POST['submit']) &&  $_POST['submit'] == 'Submit') {

And your mail parameters are not correct like boug said.

心病无药医 2024-11-14 00:33:39

您有 2 个错误

  1. 首先:

    if (isset($_POST['提交']))
    // $_POST 区分大小写
    
  2. 第二:

    if (isset($_POST['your_email']))
    // 你没有名为“your_email”的输入
    

You have 2 errors

  1. first:

    if (isset($_POST['submit']))
    // $_POST is case sensitive
    
  2. second:

    if (isset($_POST['your_email']))
    // you dont have an inout named 'your_email'
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文