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

HTML form to Email

the mail() function

Moderators: macek, egami, gesf

HTML form to Email

Postby Narayanan » Mon Aug 20, 2012 12:36 am

Hi,

First of all am the beginner please help me out.
I have used the following code in php for sending a email directly from my page but it is not working.
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$email = $_POST['email'];
$contact_no = $_POST['contact_no'];

//Validate first
if(empty($name)||empty($email))
{
echo "Name and email are mandatory!";
exit;
}

if(IsInjected($email))
{
echo "Bad email value!";
exit;
}

$email_from ='forms@stockshasthra.in';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $contact_no".

$to = "narayanan@stockshasthra.in";//<== update the email address
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-youl');


// Function to validate against any email injection attempts
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;
}
}

?>
The error is after submitting is:
error; you need to submit the form!
Warning: Cannot modify header information - headers already sent by (output started at D:\INETPUB\VHOSTS\stockshasthra.in\httpdocs\form-to-email.php:5) in D:\INETPUB\VHOSTS\stockshasthra.in\httpdocs\form-to-email.php on line 35

:help: Thanks in advance
Narayanan
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Aug 20, 2012 12:25 am

Re: HTML form to Email

Postby Acesystech » Tue Aug 21, 2012 1:30 am

please try this...

$headers =$headers .= "Content-type: text/html; charset=iso-8859-1rn";
Acesystech
New php-forum User
New php-forum User
 
Posts: 35
Joined: Mon Aug 20, 2012 10:27 pm
Location: Ernakulam

HTML form to Email

Postby sivakami » Tue Sep 04, 2012 11:57 pm

email
sivakami
New php-forum User
New php-forum User
 
Posts: 17
Joined: Tue Sep 04, 2012 11:26 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 2 guests

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