2017-01-24 7 views
-4

Я хочу создать форму обратной связи с использованием html и php, я использую Xampp и linux mint как ОС. Форма обратной связи не возвращает никакой ошибки, но она не отправляет почту. просмотрите мой PHP-код.почта() функция в linux используя lampp

<?php 
$myemail = "[email protected]"; 
    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-кодом, если это необходимо.

+1

Что вы пробовали до сих пор? – AbhiNickz

+0

Я обновил свой запрос – user7108953

+0

Соответствует ли это первому полю в обоих файлах? Если да, то то, что вам нужно, это хэш. – Sobrique

ответ

3

Это слишком сложно - корень вашей проблемы заключается в том, что вы фактически не меняете $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" ; 
}