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

Simple mail question

the mail() function

Moderators: macek, egami, gesf

Simple mail question

Postby inkfast » Fri Feb 03, 2012 6:30 pm

I've been a CF Dev for 12 years and have decided to take on PHP, so may I just say up front, nice to meet all of you!

I'm attempting to configure a simple mail script a client downloaded somewhere and where it's getting me is when it has more than two fields. Either no email or email with blank body.

The original script is:

<?php
if ( isset ( $_POST [ 'buttonPressed' ])){
$to = 'wherever' ;
$subject = 'From PHP contact page' ;
$message = $_POST [ "message" ];
$headers = 'From: ' . $_POST [ "from" ] . PHP_EOL ;
mail ( $to , $subject , $message , $headers );
header("Location: wherever");}
else {
?>

My modified version has another form field so I have named them message1 and message2:

<?php
if ( isset ( $_POST [ 'buttonPressed' ])){
$to = 'wherever' ;
$subject = 'From PHP contact page' ;
$message1 = $_POST [ "message1" ];
$message2 = $_POST [ "message2" ];
$headers = 'From: ' . $_POST [ "from" ] . PHP_EOL ;
mail ( $to , $subject , $message1 , $message2 , $headers );
header("Location: wherever");}
else {
?>

I've been looking at PHP code sites all afternoon and it seems there are a number of ways of doing this but I haven't been able to get any to work. I bought a book on Amazon for PHP5 (my version is 5.3.8 I believe) and I'm waiting for it to arrive.

Thanks!
David
inkfast
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Feb 03, 2012 6:16 pm

Re: Simple mail question

Postby rupali » Fri Feb 03, 2012 6:50 pm

try this way,

<?php
if ( isset($_POST[ 'buttonPressed' ]))
{
$to = 'wherever' ;
$subject = 'From PHP contact page' ;
$message = $_POST[ "message" ];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $_POST [ "from" ] . PHP_EOL ;
mail($to,$subject,$message,$headers);
header("Location: wherever");
}
?>
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA


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.

cron