【问题标题】:mail () function in linux using lampplinux中使用lampp的mail()函数
【发布时间】:2017-06-09 04:47:54
【问题描述】:

我想使用 html 和 php 创建反馈表,我使用 Xampp 和 linux mint 作为操作系统。反馈表没有返回任何错误,但也没有发送任何邮件。请检查我的 php 代码。

<?php
$myemail  = "deepshikha@yahoo.com";
    if (isset($_GET['yourname']) && $_GET['yourname'] !== '  '){

    $yourname = $_GET['yourname'];
    }
    if (isset($_GET['subject']) && $_GET['subject'] !== '  '){

    $subject = $_GET['subject'];
    }
    if (isset($_GET['email']) && $_GET['email'] !== '  '){

    $email = $_GET['email'];
    }
    if (isset($_GET['website']) && $_GET['website'] !== '  '){

    $website = $_GET['website'];
    }
    if (isset($_GET['likeit']) && $_GET['likeit'] !== '  '){

    $likeit = $_GET['likeit'];
    }
    if (isset($_GET['comments']) && $_GET['comments'] !== '  '){

    $comments = $_GET['comments'];
    }
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
  {
show_error("E-mail address not valid");
 }
  if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
  {
    $website = '';
   }
   $message = "Hello!

   Your contact form has been submitted by:

  Name: $yourname
   E-mail: $email
   URL: $website

   Like the website? $likeit

  Comments:
  $comments

   End of message
   ";
  if(mail($myemail,$subject,$message)){
  header('Location: thanks.htm');
  }else{
 echo "Message could not be sent...";
  }
  exit();
   function check_input($data, $problem='')
   {
        $data = trim($data);
          $data = stripslashes($data);
           $data = htmlspecialchars($data);
         if ($problem && strlen($data) == 0)
           {
         show_error($problem);
           }
           return $data;
           }

         function show_error($myError)
        {
     ?>
     <html>
     <body>

     <b>Please correct the following error:</b><br />
     <?php echo $myError; ?>

     </body>
     </html>
   <?php
   exit();
   }
   ?>

我找不到问题出在哪里?如果有人可以提供帮助,我将不胜感激。 如果需要,我也可以分享 HTML 代码。

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 我已经更新了我的查询
  • 两个文件的第一个字段是否匹配?如果是这样,那么您需要的是哈希。

标签: php xampp


【解决方案1】:

这太复杂了 - 你的问题的根源是你实际上并没有改变$V_name,所以......它每次都会打印它。

但是鉴于您的示例数据,这将满足您的要求:

#!/usr/bin/env perl
use strict;
use warnings;

#read the first file into a hash. 
my %first_input;

open ( my $input, '<', 'test1.txt') or die $!;
while ( <$input> ) {
   my ( $key, @fields ) = split /\t/ ;
   $first_input{$key} = [@fields];
}

open ( my $second_file, '<', 'test2.txt' ) or die $!;
#iterate the second file - use the first field as a 'key' and 
#look it up from the hash we created from the first file. 
while ( <$second_file> ) {
   my ( $key, @fields ) = split /\t/; 
   print join "\t", $key, @fields , @{$first_input{$key}}, "\n" ;
}

【讨论】:

    猜你喜欢
    • 2013-02-17
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    相关资源
    最近更新 更多