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


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.
//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
echo "Name and email are mandatory!";

echo "Bad email value!";

$email_from ='';//<== 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 = "";//<== update the email address
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
//done. redirect to thank-you page.
header('Location: thank-youl');

// Function to validate against any email injection attempts
function IsInjected($str)
$injections = array('(\n+)',
$inject = join('|', $injections);
$inject = "/$inject/i";
return true;
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\\httpdocs\form-to-email.php:5) in D:\INETPUB\VHOSTS\\httpdocs\form-to-email.php on line 35

:help: Thanks in advance
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";
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

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 1 guest

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