mailing form

the mail() function

Moderators: egami, macek, gesf

Post Reply
TheProdigyGuy
New php-forum User
New php-forum User
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Wed Dec 14, 2011 3:25 pm

Hi ninJo.
You have no HTML Submission form on that code.
Here is my way:
BTW,message format will be:

Code: Select all

########################################
User IP: 192.168.0.1
Browser: Mozilla/5.0 (Windows NT xx; rv:x.x.x.x.x) Gecko/xxxxxx xxxxxx Chrome xxxxxx
Name: UFO
Surname: Anonymouse
Country: Mercury
City: not exist
Tel No: 00012121
Contact Mail Address: admin@localhost.com
Message: This is a first message!
Hey Humaaaaaaaans!
It Works!))
########################################

Here is :

Code: Select all

<?php
error_reporting('off');
$page=<<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form</title>
</head>
<body>
<center><br /><br /><br /><br /><br />
<form method="post" action="">
  <label>&nbsp;Name*&nbsp;&nbsp;&nbsp;&nbsp;
  <input type="text" name="Adiniz" id="Adiniz" />
  </label>

  <p>
    <label>&nbsp;Surname*&nbsp;
    <input type="text" name="Surname" id="Surname" />
    </label>
  </p>
  
  
    <p>
    <label>&nbsp;&nbsp;Country*&nbsp;
    <input type="text" name="country" id="country" />
    </label>
  </p>
  
    <p>
    <label>&nbsp;&nbsp;&nbsp;City*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="city" id="city" />
    </label>
  </p>
  
    <p>
    <label>&nbsp;&nbsp;Tel&nbspNo*&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="tel" id="tel" />
    </label>
  </p>
  
  
  
  <p>
    <label>&nbsp;&nbsp;Email*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="Email" id="Email" />
</label>
  </p>
  <p>
    <label>&nbsp;Message *<br />
    &nbsp;</label>
    <label>
    <textarea name="Body" cols="31" rows="10" wrap="virtual" id="Body"></textarea>
    </label>

  </p>
<p>
  <input type="submit" name="submit" value="submit" />
</p>
</form>
</center>
</body>
</html>


HTML;

echo $page;
//echo count($_POST);

$yourmailaddr='test@mymail.com'; // Enter your Valid e-mail address here.

if (count($_POST)==0) die;
if (isset($_POST['Adiniz']) && isset($_POST['Surname']) && isset($_POST['country']) && isset($_POST['city']) && isset($_POST['tel']) &&isset($_POST['Email']) && isset($_POST['Body']) && !empty($_POST['Adiniz']) && !empty($_POST['Surname']) && !empty($_POST['country']) && !empty($_POST['city']) && !empty($_POST['tel']) && !empty($_POST['Email']) && !empty($_POST['Body']))
  { 
$adi=htmlspecialchars($_POST['Adiniz']);
$soyadi= htmlspecialchars($_POST['Surname']);
$country=htmlspecialchars($_POST['country']);
$city=htmlspecialchars($_POST['city']);
$telno=htmlspecialchars($_POST['tel']);

//!empty($_POST['country']) && !empty($_POST['city']) && !empty($_POST['tel'])
if (!filter_var(htmlspecialchars($_POST['Email']), FILTER_VALIDATE_EMAIL)) die('<script>alert("Your Mail Address is not Correct!");location.replace("?error");</script>');
$emailadresi=filter_var(htmlspecialchars($_POST['Email']), FILTER_VALIDATE_EMAIL);
$metni=htmlspecialchars($_POST['Body']);
        
        if (@mail($yourmailaddr,"You've got NeW Feedback!",
                   str_repeat('#',40) . PHP_EOL .
                   'User IP: ' . $_SERVER['REMOTE_ADDR'] . PHP_EOL .
                   'Browser: ' . htmlspecialchars($_SERVER['HTTP_USER_AGENT']) .PHP_EOL .
                   'Name: ' . $adi . PHP_EOL .
                   'Surname: ' . $soyadi . PHP_EOL .
                   'Country: ' . $country . PHP_EOL .
                   'City: ' . $city . PHP_EOL .
                   'Tel No: ' . $telno . PHP_EOL .
                   'Contact Mail Address: ' . $emailadresi . PHP_EOL .
                   'Message: ' . wordwrap($metni,70) . PHP_EOL . str_repeat('#',40)).PHP_EOL)
        
        {
            die('<script>alert("Your FeedBack Sent! Thank You!");location.replace("?success");</script>');
        }
        else
        {
            die('<script>alert("Theris and error! Please try Again.");location.replace("?error");</script>');
            
        }
        
        
    }
    else
    {
        die('<script>alert("Can not send your Feedback!.Reason: Incorrect Input!");location.replace("?error");</script>');
    }


?>

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests