Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

My first mail form

the mail() function

Moderators: macek, egami, gesf

My first mail form

Postby Gambon » Tue May 24, 2011 5:20 am

Hi folks,

I wonder if somebody can help me with 2 simple problems with my form.

Here is the html form:

Code: Select all
<form action="send_mail.php" method="post">
<div style="height:30px;"><input class="input_txt2" value="Name: " name="Name" type="text" /></div>
<div style="height:30px;"><input class="input_txt2" value="Email: " name="Email" type="text" /></div>
<div style="height:30px;"><input class="input_txt2" value="Subject: " name="Subject" type="text" /></div>
<div><textarea class="text_area2" cols="32" rows="5" name="Comments">Message: </textarea></div>
<input class="submit2" name="reset" type="submit" value="Submit" />
</div>
</form>


Here is the PHP script with my email blanked:

Code: Select all
<?php

$feedback_page = "contact_us.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";

$To = "support@mycorrectdomain.com";
$Email = $_REQUEST['Email'] ;
$Comments = $_REQUEST['Comments'] ;
$Name = $_REQUEST['Name'] ;
$Subject = $_REQUEST['Subject'] ;
$Header = "From: $Name <$Email>" ;



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 the user tries to access this script directly, redirect them to the feedback form,
if (!isset($Email)) {
header( "Location: $feedback_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($Email) || empty($Name) || empty($Subject) || empty($Comments)  ) {
header( "Location: $error_page" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($Email) ) {
header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
$send_contact=mail($To,$Subject,$Comments,$Header);
header( "Location: $thankyou_page" );
}
?>


Email arrives ok.
Problem no 1: The From field shows MY domain mail server as the sender.
Problem no 2: Probably part of problem 1, the Name field isn't sent anywhere either.


I'm sure it is a dead simple fix, can anybody help?
Gambon
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue May 24, 2011 5:09 am

Re: My first mail form

Postby bachans » Fri May 27, 2011 5:49 am

Hi,

Here I ve modified your code in php.

Code: Select all
<?php
if($_POST)
{
    $feedback_page = "contact_us.html";
    $error_page = "error_message.html";
    $thankyou_page = "thank_you.html";

    $To = "bachans@mindfiresolutions.com";
    $Email = $_POST['Email'] ;
    $Comments = $_POST['Comments'] ;
    $Name = $_POST['Name'] ;
    $Subject = $_POST['Subject'] ;
    $Header = "From: $Name <$Email>\r\n" ;
   
   $Header .= "Content-type: text/html\r\n";


   $Email = mail ($To, $Subject, $Comments, $Header);
   
}
?>


Thanks
Bachan
bachans
New php-forum User
New php-forum User
 
Posts: 67
Joined: Thu May 19, 2011 6:01 am
Location: India

Re: My first mail form

Postby webinfopedia » Sun May 29, 2011 6:55 pm

For simple PHP email function i have wrote an article. You can get idea about PHP mail function along with demo and example. read article below
http://www.webinfopedia.com/php-mail-function.html

Hope that it will help you.
User avatar
webinfopedia
New php-forum User
New php-forum User
 
Posts: 84
Joined: Sat May 21, 2011 10:26 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.