Current location: Hot Scripts Forums » Programming Languages » PHP » php mail


php mail

Reply
  #1 (permalink)  
Old 10-07-04, 03:44 AM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
php mail

i have a form in my index.php page where users fill in name, phone and email. how do i format the mailer.php page, ie the page recieving the form? i've tried everything i can think of but no luck...

i want the result to be that whatever the users filled into the form, it will show up in an email sent to me.

this is my form:
PHP Code:



<form action="mailer.php" method="post">
    <
table border="0" cellspacing="0" cellpadding="0">
        <
tr>
            <
td colspan="5" class="link">1. Please fill in your info and I will contact you as soon as possible.</td>
        </
tr>
        <
tr>
            <
td colspan="5" class="link"><img src="http://', $rooturl,'_images/blank.gif" width="1" height="10" border="0"></td>
        </
tr>
        <
tr>
            <
td valign="top" class="link">Name:<br>
            <
input type="text" id="name" value="Name" size="10" style="width: 140px; height: 10;"></td>
            <
td valign="top"><img src="http://', $rooturl,'_images/blank.gif" width="30" height="1" border="0"></td>
            <
td valign="top" class="link">Phone:<br>
            <
input type="text" id="phone" value="Phone" size="10" style="width: 140px; height: 10;"></td>
            <
td valign="top"><img src="http://', $rooturl,'_images/blank.gif" width="30" height="1" border="0"></td>
            <
td valign="top" class="link">Email:<br>
            <
input type="text" id="email" value="Email" size="10" style="width: 140px; height: 10;"></td>
        </
tr>
        <
tr>
            <
td colspan="5" class="link" align="left"><img src="http://', $rooturl,'_images/blank.gif" width="1" height="15" border="0"></td>
        </
tr>
        <
tr>
            <
td colspan="3" class="link">2. Check the tracks you like</td>
            <
td colspan="2" class="link" align="right"><input type="submit" id="Submit" value="Send your info"></td>
        </
tr>
        <
tr>
            <
td colspan="5" class="link" align="left"><img src="http://', $rooturl,'_images/blank.gif" width="1" height="5" border="0"></td>
        </
tr>
    </
table>
    <
input type="hidden" id="Who" value="',  $who,'"><input type="hidden" id="Page" value="', $page,'"

</
form
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-07-04, 03:00 PM
bizzar528's Avatar
bizzar528 bizzar528 is offline
Community Liaison
 
Join Date: Sep 2004
Location: Pennsylvania, US
Posts: 1,551
Thanks: 2
Thanked 16 Times in 15 Posts
Reference: http://us4.php.net/manual/en/function.mail.php

======================

mailer.php
-----------------
Code:
<?
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

$to = "youremail@yourdomain.com";
$subject = "form response";

$message="
<html>
<head>
 <title>Title of Page</title>
</head>
<body>
Name = ".$name."<br>
Phone = ".$phone."<br>
Email = ".$email."
</body>
</html>
";

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$name."<".$email.">\r\n";

if (mail($to, $subject, $message, $headers)) { header("Location: index.php"); }
?>
Very simple idea here. I'm not a pro php programmer, but this is how I've been doing my forms. First, you call in your form variables from a POST statement. Then, select your TO address and SUBJECT line.

I format messages via HTML. If you don't do formatting, you end up with just plain text. Depends on how you want to receive it. I'd do a plain text version here in a second.

Then my script adds the headers so the email comes as an HTML email.

Upon successful send (the last line / if statement) then it redirects to a confirmation page. I put index.php just cause.

For plain text formatting, use this code instead.

mailer.php
-----------------
Code:
<?

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

$to = "youremail@yourdomain.com";
$subject = "form response";

$message = "
Name = ".$name."\r\n
Phone = ".$phone."\r\n
Email = ".$email;

$headers = "From: ".$name."<".$email.">\r\n";

if (mail($to, $subject, $message, $headers)) { header("Location: index.php"); }

Last edited by bizzar528; 10-07-04 at 03:04 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-07-04, 04:13 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Here's a script I think you'l find a lot easier nd it also using js to check to see if all forms are filled out:
PHP Code:

<HTML>

<HEAD>
<TITLE>Contact</TITLE>
<script language="JavaScript" type="text/javascript">
function checkform ( form )
{
  if (form.name.value == "") {
    alert( "Please enter your name/handle." );
    form.name.focus();
    return false ;
  }
  if (form.subject.value == "") {
    alert( "Please enter a subject." );
    form.email.focus();
    return false ;
  }
    if (form.email.value == "") {
    alert( "Please enter an email address." );
    form.email.focus();
    return false ;
  }
  if (form.message.value == "") {
    alert( "Please enter a message." );
    form.message.focus();
    return false ;
  }

  return true ;
}
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<link rel="stylesheet" href="style.css" type="text/css">
</HEAD>
<BODY BGCOLOR="#CCCCCC" TEXT="#999999">
<?php

if(!isset($_POST["subject"]) AND !isset($_POST["email"]) AND !isset($_POST["name"]) AND !isset($_POST["message"])){
    
$self $_SERVER["PHP_SELF"];
    
$form '<form action="' $self '" method="post" onsubmit="return checkform(this);"><input type="text" name="name" value="Name"><br><input type="text" name="subject" value="Subject"><br><input type="text" name="email" value="E-mail address"><br><TEXTAREA name="message" ROWS=12 COLS=80 wrap="on"></TEXTAREA><br><input type="submit" value="Submit"><input type="reset">';
    echo(
$form);
}
elseif(isset(
$_POST["subject"]) AND isset($_POST["email"]) AND isset($_POST["name"]) AND isset($_POST["message"])){
    
$email1 $_POST["email"];
    if(
strpos($email1'@') !== false) {
        
$email2 explode("@",$email1);
        
$email3 count($email2);
        if(
$email3 3){
            
$string "Please enter a valid e-mail address.";
        }
        else{
            
$test_url 'http://' $email2[1];
            if(!@
fopen($test_url,"r")){
                
$string1 "Please enter a valid e-mail address.";
            }
            else{
                
$name $_POST["name"];
                
$subject1 $_POST["subject"];
                
$subject 'Form Mailer: ' $subject1;
                
$message1 $_POST["message"];
                
$ip $_SERVER['REMOTE_ADDR'];
                
$date date("m/d/y");
                
$time date("h:i a");
                
$message $message1 '<hr>Ip: <b>' $ip '</b> Time: <b>' $time '</b> Date: <b>' $date '</b>';
                if(
mail("your@email"$subject$message)){
                    
$string "Mail sent...";
                }
                else{
                    
$string "Mail error....";
                }
            }
        }
            
    }
    else{
            
$string "Please enter a valid e-mail address.";
        }    
}
if(isset(
$string)){
    echo(
$string);
}
?>

</BODY>
</HTML>
BTW: I wrote that so if you use it please give me credit. Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-07-04, 09:41 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
thanks to both of you! i'll check them out tonight.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-07-04, 10:16 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
i tried both of your scrips, copy and pasted into mailer.php - no luck!
the emails we're sent with bizzar's script but no information from my form was passed on to the email. eclipse, i couldn't get your script working at all.

now, i'm sure both scrippts are just fine, maybe i'm soing something wrong...


i had another script that was emailing me but without content from my form..:

PHP Code:

<? 

 $to 
"xxx@xxx.com";
 
$from 'From: \"$name\" <$email>';
 
$subject "Message from www.camo.biz" $subject;

 
$additional "$from\r\nReply-To: $email\r\nContent-Type: text/html; charset=iso-8859-1";

 
mail($to$subject$message$additional);
 
?>



and everyone tells me mailer are so easy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-07-04, 10:42 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Well what error did you get from mine cause I've tested it on 4.3.1, 4.3, 5.0, and 5.0.1 with any problems.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-11-04, 08:23 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Eclipse
Well what error did you get from mine cause I've tested it on 4.3.1, 4.3, 5.0, and 5.0.1 with any problems.
i got this "Parse error: parse error in /Library/WebServer/Documents/mailer.php on line 47"

i tried fixing it but no luck...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 10-11-04, 08:27 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
i'm just looiking for something reall reall ysimple that will carry the info from my form on the index.php page over to the mailer.php page. this mailer.php page should email me a result of the form, looking something like this:

input1: text1
input2: text2
input3: text3

etc etc





this script:
PHP Code:

<? 

 $to 
"xxx@xxx.com"
$from 'From: \"$name\" <$email>'
$subject "Message from www.camo.biz" $subject

$additional "$from\r\nReply-To: $email\r\nContent-Type: text/html; charset=iso-8859-1"

mail($to$subject$message$additional); 
?>

emailed me alright but did not carry any data over from the form.

oh trouble oh trouble.....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 10-11-04, 08:46 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Ok just try this:
PHP Code:

<HTML>

<HEAD>
<TITLE>Contact</TITLE>
<script language="JavaScript" type="text/javascript">
function checkform ( form )
{
  if (form.name.value == "") {
    alert( "Please enter your name/handle." );
    form.name.focus();
    return false ;
  }
  if (form.subject.value == "") {
    alert( "Please enter a subject." );
    form.email.focus();
    return false ;
  }
    if (form.email.value == "") {
    alert( "Please enter an email address." );
    form.email.focus();
    return false ;
  }
  if (form.message.value == "") {
    alert( "Please enter a message." );
    form.message.focus();
    return false ;
  }

  return true ;
}
</script>
</HEAD>
<BODY BGCOLOR="#CCCCCC" TEXT="#999999">
<?php

if(!isset($_POST["subject"]) AND !isset($_POST["email"]) AND !isset($_POST["name"]) AND !isset($_POST["message"])){
    
$self $_SERVER["PHP_SELF"];
    
$form '<form action="' $self '" method="post" onsubmit="return checkform(this);"><input type="text" name="name" value="Name"><br><input type="text" name="subject" value="Subject"><br><input type="text" name="email" value="E-mail address"><br><TEXTAREA name="message" ROWS=12 COLS=80 wrap="on"></TEXTAREA><br><input type="submit" value="Submit"><input type="reset">';
    echo(
$form);
}
elseif(isset(
$_POST["subject"]) AND isset($_POST["email"]) AND isset($_POST["name"]) AND isset($_POST["message"])){
    
$email1 $_POST["email"];
    if(
strpos($email1'@') !== false) {
        
$email2 explode("@",$email1);
        
$email3 count($email2);
        if(
$email3 3){
            
$string "Please enter a valid e-mail address.";
        }
        else{
            
$test_url 'http://' $email2[1];
            if(!@
fopen($test_url,"r")){
                
$string1 "Please enter a valid e-mail address.";
            }
            else{
                
$name $_POST["name"];
                
$subject1 $_POST["subject"];
                
$subject 'Form Mailer: ' $subject1;
                
$message1 $_POST["message"];
                
$ip $_SERVER['REMOTE_ADDR'];
                
$date date("m/d/y");
                
$time date("h:i a");
                
$message $message1 '<hr>Ip: <b>' $ip '</b> Time: <b>' $time '</b> Date: <b>' $date '</b>';
                if(
mail("your@email"$subject$message)){
                    
$string "Mail sent...";
                }
                else{
                    
$string "Mail error....";
                }
            }
        }
            
    }
    else{
            
$string "Please enter a valid e-mail address.";
        }    
}
if(isset(
$string)){
    echo(
$string);
}
?>

</BODY>
</HTML>
I'm using that on my site www.eclipsethenet.us/contact.php so it's just your server if it doesn't work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 10-12-04, 02:19 AM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
case closed!

sorry to have wasted your time with my incompetence.... my form was not coded right....





it works now....



thanks to all the contributions!!
your help is always appreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i work with PHP mail() function darkcarnival PHP 5 08-31-09 06:11 PM
mail script php in safe mode ellakai PHP 0 08-23-04 01:00 AM
Attach files to your form mail using PHP OMID SOFT Script Requests 0 04-17-04 08:26 PM
Open source PHP Mail Script jewellgr Website Reviews 1 08-18-03 04:30 PM


All times are GMT -5. The time now is 01:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.