Php Form To Mail

A Member? Please Login  
type your username and password to login
Date: September 08, 2008, 06:43 PM
237624 members and 137373 Topics
Latest Member: tunexd
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Php Form To Mail
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Php Form To Mail  (Read 409 views)
jozzy
Php Form To Mail
« on: February 05, 2007, 01:58 PM »

Can any one help me out how can i get php form to email  script
kengimel (m)
Re: Php Form To Mail
« #1 on: February 06, 2007, 11:00 AM »

Well i think this will help you http://formtoemail.com/
jozzy
Re: Php Form To Mail
« #2 on: February 06, 2007, 11:43 AM »

Thank for that, but there is one i see you just put your feed back link, thank link and error link you send then it give you the code if i could get something like that because the link you get me i not know how to use it if only you can put on
alexis (m)
Re: Php Form To Mail
« #3 on: February 06, 2007, 09:21 PM »

tell the fields you want to use so that I can guide you how to build one
jozzy
Re: Php Form To Mail
« #4 on: February 07, 2007, 02:40 AM »

Thank for your reply, this is my code from the form when my feedback page is tag fback.php, the confirmation page is tag feedthank.php, and the error page is tag error.php, why the mail i want to add is barsplusplus@yahoo.com so you can check the code below and put me through

 <form action="feedback.php" method="post" name="feedback" target="_self" id="form" >
  <br>
  <div  style="position:absolute; text-align: left; left: 31px; top: 23px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #2A7FAA; font-size: 12px; width: 85px; height: 15px; font-weight: 400;">FIRST NAME :   </div> 
    <div  style="position:absolute; text-align: left; left: 166px; top: 19px;">
    <input type="text" size="30" name="name_first" ></div>
    <br>
    <div  style="position:absolute; left: 30px; top: 51px; width: 87px; text-align: left; font-weight: 400; font-size: 12px; color: #2A7FAA;">LAST NAME:</div>       
    <div  style="position:absolute; text-align: left; left: 166px; top: 47px;">
    <input type="text" size="30" name="name_last" ></div>
    <br>
    <div  style="position:absolute; left: 30px; top: 77px; width: 70px; text-align: left; font-weight: 400; font-size: 12px; color: #2A7FAA;">CHAPTER:</div>
    <div  style="position:absolute; text-align: left; left: 166px; top: 74px;">
    <input type="text" size="30" name="_chapter" ></div>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 107px; font-weight: 400; font-size: 12px; color: #2A7FAA;">ZONE:</div>
    <div  style="position:absolute; text-align: left; top: 102px; left: 166px;">
      <select name="_zone" size="1" >
         <option value="n_central">NORTH-CENTRAL</option>
      <option value="n_east">NORTH-EAST</option>
      <option value="n_west">NORTH-WEST</option>
      <option value="s_east">SOUTH-EAST</option>
      <option value="s_south">SOUTH-SOUTH</option>
      <option value="s_west">SOUTH-WEST</option>
      <option value="select" selected>Please select</option>
    </select></div>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 137px; width: 120px; color: #2A7FAA; font-weight: 400; font-size: 12px;">E-MAIL ADDRESS:</div>
    <div  style="position:absolute; text-align: left; top: 132px; left: 166px;">
    <input type="text" name="_e-mail" size="30" ></div>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 165px; width: 107px; color: #2A7FAA; font-size: 12px; font-weight: 400;">PHONE NO.:</div>
    <div  style="position:absolute; text-align: left; top: 161px; left: 166px;">
    <input type="text" name="_phone" size="30" ></div>
    <br>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 228px; font-size: 12px; font-weight: 400; color: #2A7FAA;">COMMENT:</div>
    <div  style="position:absolute; text-align: left; left: 166px; top: 216px;">
    <textarea name="_comment" cols="35" rows="7" ></textarea></div>
   <br>
   <br>
   <br>
   <div  style="position:absolute; top: 369px; left: 237px; text-align: left;">
    <input type="submit" name="submit" value="SEND MESSAGE" /></div>
  </form>
  <div id="flash" style="position:absolute; left:158px; top:700px; width:682px; height:80px; z-index:5">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="675" height="75">
      <param name="movie" value="anime/IF%2007.swf">
      <param name="quality" value="high">
      <embed src="anime/IF%2007.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="675" height="75"></embed>
    </object>
  </div>
  <div id="footer" style="position:absolute; left:158px; top:800px; width:673px; height:26px; z-index:6" class="text">
    <div align="left"><a href="contacts.php"  target="_self" onmouseover="window.status='Click to see our contact info'; return true;"
                     onmouseout="window.status=''; return true;">Contact us</a> | <a href="fback.php" target="_self" onmouseover="window.status='Click to send feedback to us'; return true;"   onmouseout="window.status='';  return true;">Feedback</a><br>
&copy; Copyright 2006 - 2007. Bar++ Initiative . All right reserved.</div>
  </div>
</div>
</body>
</html>
xanadu
Re: Php Form To Mail
« #5 on: February 10, 2007, 03:05 AM »

Hi jozzy,

Came across your post and thought I should contribute my twopence worth.

I have written a little script that should do what you want - a page called fthank.php (which processes your form, sends the email, generates an error if necessary and displays a thank you/confirmation message if the post is successful). So instead of three pages as you stated in your post, you could use two (to be more efficient, you could actually do it all on one page, but lets leave it at this for now).

I have tried to comment the script as much as possible to help you understand the steps. Feel free to post a reply if you do not understand any of the steps.

Here's fback.php (your form) - note that I have amended the "action" in the form tag to point to 'fthank.php'.

Quote
<form action="fthank.php" method="post" name="feedback" target="_self" id="form" >
  <br>
  <div  style="position:absolute; text-align: left; left: 31px; top: 23px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #2A7FAA; font-size: 12px; width: 85px; height: 15px; font-weight: 400;">FIRST NAME :   </div> 
    <div  style="position:absolute; text-align: left; left: 166px; top: 19px;">
    <input type="text" size="30" name="name_first" ></div>
    <br>
    <div  style="position:absolute; left: 30px; top: 51px; width: 87px; text-align: left; font-weight: 400; font-size: 12px; color: #2A7FAA;">LAST NAME:</div>       
    <div  style="position:absolute; text-align: left; left: 166px; top: 47px;">
    <input type="text" size="30" name="name_last" ></div>
    <br>
    <div  style="position:absolute; left: 30px; top: 77px; width: 70px; text-align: left; font-weight: 400; font-size: 12px; color: #2A7FAA;">CHAPTER:</div>
    <div  style="position:absolute; text-align: left; left: 166px; top: 74px;">
    <input type="text" size="30" name="_chapter" ></div>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 107px; font-weight: 400; font-size: 12px; color: #2A7FAA;">ZONE:</div>
    <div  style="position:absolute; text-align: left; top: 102px; left: 166px;">
      <select name="_zone" size="1" >
         <option value="n_central">NORTH-CENTRAL</option>
      <option value="n_east">NORTH-EAST</option>
      <option value="n_west">NORTH-WEST</option>
      <option value="s_east">SOUTH-EAST</option>
      <option value="s_south">SOUTH-SOUTH</option>
      <option value="s_west">SOUTH-WEST</option>
      <option value="select" selected>Please select</option>
    </select></div>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 137px; width: 120px; color: #2A7FAA; font-weight: 400; font-size: 12px;">E-MAIL ADDRESS:</div>
    <div  style="position:absolute; text-align: left; top: 132px; left: 166px;">
    <input type="text" name="_e-mail" size="30" ></div>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 165px; width: 107px; color: #2A7FAA; font-size: 12px; font-weight: 400;">PHONE NO.:</div>
    <div  style="position:absolute; text-align: left; top: 161px; left: 166px;">
    <input type="text" name="_phone" size="30" ></div>
    <br>
    <br>
    <div  style="position:absolute; text-align: left; left: 30px; top: 228px; font-size: 12px; font-weight: 400; color: #2A7FAA;">COMMENT:</div>
    <div  style="position:absolute; text-align: left; left: 166px; top: 216px;">
    <textarea name="_comment" cols="35" rows="7" ></textarea></div>
   <br>
   <br>
   <br>
   <div  style="position:absolute; top: 369px; left: 237px; text-align: left;">
    <input type="submit" name="submit" value="SEND MESSAGE" /></div>
  </form>
  <div id="flash" style="position:absolute; left:158px; top:700px; width:682px; height:80px; z-index:5">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="675" height="75">
      <param name="movie" value="anime/IF%2007.swf">
      <param name="quality" value="high">
      <embed src="anime/IF%2007.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="675" height="75"></embed>
    </object>
  </div>
  <div id="footer" style="position:absolute; left:158px; top:800px; width:673px; height:26px; z-index:6" class="text">
    <div align="left"><a href="contacts.php"  target="_self" onmouseover="window.status='Click to see our contact info'; return true;"
                     onmouseout="window.status=''; return true;">Contact us</a> | <a href="fback.php" target="_self" onmouseover="window.status='Click to send feedback to us'; return true;"   onmouseout="window.status='';  return true;">Feedback</a><br>
&copy; Copyright 2006 - 2007. Bar++ Initiative . All right reserved.</div>
  </div>
</div>
</body>


Now here's fthank.php - the processor/confirmation/error page:

Quote
<?
//===get the data submitted, store them to variables

$first_name=$_POST['name_first'];
$last_name=$_POST['name_last'];
$chapter=$_POST['_chapter'];
$zone=$_POST['_zone'];
$email=$_POST['_e-mail'];
$phone=$_POST['_phone'];
$comment=$_POST['_comment'];


//===The following message will be sent if post is successful. You can amend this to read whatever you want, just keep your message between the double quotes. '\n' indicates a return, that is going to the next line, so '\n\n' means double-spacing

$message="Hello, a visitor to your site has submitted a message.\n\nThe details are:\n\nFirst name: $first_name\nLast Name: $last_name\nChapter: $chapter\nZone: $zone\nEmail: $email\nPhone: $phone\nComment: $comment\n\n";

//==check that all fields have been completed - if not, prompt user to enter the required data. Note: Do the steps below for each field you want to be required. My example ensures that all fields are required and MUST be filled. If you do not want a field to be required, simply remove that portion, and the script will not validate it. We use a bit of javascript to send user back to form page.

if ($first_name=="") {
  echo "<p><center><font color='red'>Please enter your first name</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

elseif ($last_name=="") {
  echo "<p><center><font color='red'>Please enter your last name</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

elseif ($chapter=="") {
  echo "<p><center><center><font color='red'>Please enter your chapter</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

elseif ($zone=="select") {
  echo "<p><center><center><font color='red'>Please select a zone</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

elseif ($email=="") {
  echo "<p><center><font color='red'>Please enter your email</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}


//===Also check if a valid email address has been entered i.e an address with invalid characters

elseif (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<p><center><font color='red'>You have entered an invalid email address or none at all </font>";
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}


elseif ($phone=="") {
  echo "<p><center><font color='red'>Please enter your phone</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

elseif ($comment=="") {
  echo "<p><center><font color='red'>Please enter a comment</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

//===Now if all validation is successful, send mail. Note the pattern: your email address, the subject of the mail, the actual message - which we declared above, and an address where it is coming from - your choice

else {
mail("barsplusplus@yahoo.com", "Message Submission", $message, "From: yoursite@yahoo.com");


//===Having sent the mail, paste a thank you message. You can edit this to read what you want.

echo "<p><center>Thank you for sending a message. Stay well!";

//== you can then offer user a link to any other page on your site, eg your home page
echo "<p><center><a href='index.php'>Back to home page</a>";

}
?>


Any queries, do post a reply.

jozzy
Re: Php Form To Mail
« #6 on: February 13, 2007, 05:06 AM »

Hello xanadu,
thank very much have try it but i still can get it because is not send all it dos it just care all i input in the form when i try it may be it will send to my mail box please do put me through
xanadu
Re: Php Form To Mail
« #7 on: February 14, 2007, 12:49 PM »

jozzy,

i have tested the scripts, and can assure you they both work. howare you running them? All you have to do is copy the scripts as I have pasted them in the earlier post, and paste them in .php files. Then place them in the same directory on your server. What server are you running them on, anyway?
iilenloa (m)
Re: Php Form To Mail
« #8 on: February 23, 2007, 11:37 AM »

Hi, before the php mail function can work, make sure you have an SMTP server installed on the server where the PHP server is. I mean there must be an SMTP (Simple Mail Transfer Protocol) server installed on the server. It is the SMTP server that recieves the request and sends the mail. If there is no SMTP server installed on the server, the mail won't be sent. There are ways to test if the SMTP server software is installed. here it is;

Code:
<?php

$mailserver
= 'mail.google.com';
$mailport = 25;
$from = 'iilenloa@gmail.com';
$to = 'cujuokonkwo@yahoo.com';
$fsock = @fsockopen($mailserver,$mailport,$erno,$erstr,10);
$log = array();
$log['Response'] = @fgets($fsock);
if(empty(
$log['Response'])){
$log['Response'] = 'No response from "'.$mailserver.'" OR cannot connect to host on port '.$mailport.'';
}


$inimailserver = ini_get('SMTP');
$inimailserverport = ini_get('smtp_port');
//print $inimailserver;

print "Checking if the \"$mailserver\" is reachable, <hr>";

print
'<table border=1>';
foreach(
$log as $key => $value){
print <<<EOS
<tr><th>$key</th><td>$value</td></tr>
EOS;}
print
'</table>';

print <<<HERE
<table border=1>
<tr>
<th>Default SMTP Server</th><td>$inimailserver</td>
</tr>
<tr>
<th>Default SMTP Server Port</th><td>$inimailserverport</td>
</tr>
</table>
HERE;
print
"<hr>Checking if the default SMTP server is reachable, <hr>";
$fsock2 = @fsockopen($inimailserver,$inimailserverport,$erno,$erstr,10);
$log2 = array();
$log2['Response'] = @fgets($fsock2);
if(empty(
$log2['Connect'])){
$log['Response'] = 'No response from "'.$inimailserver.'" OR cannot connect to host on port '.$mailport.'';
}

print
'<table border=1>';
foreach(
$log2 as $key => $value){
print <<<EOS
<tr><th>$key</th><td>$value</td></tr>
EOS;}
print
'</table>';

?>


Run the above code and check the response. That will make you know if the server has an SMTP server.
There are cases that the server might have SMTP server but the require authentication for them to send mails. However if there is an SMTP server installed, you are bound to get a positive response from the server. Thanks. Feel free to ask as many questions as you can. Mail me @ iilenloa@gmail.com, by phone 08085736614.
DevDel (m)
Re: Php Form To Mail
« #9 on: March 12, 2007, 05:51 PM »

Let's assume you know how to design your usual php form that can submit calling up any other php script,

To send to email is as basic as using codes like these:

<?php
$to = $_POST["to"];
$from = $_POST["from"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = "From: " . $from . "\r\n";

$mailsent = mail($to, $subject, $message, $headers);

if ($mailsent) {
echo "Congrats! The following message has been sent: <br><br>";
echo "<b>To:</b> $to<br>";
echo "<b>From:</b> $from<br>";
echo "<b>Subject:</b> $subject<br>";
echo "<b>Message:</b><br>";
echo $message;
} else {
echo "There was an error, ";
}
?>

to,from,subject,message being field names from your form
DevDel (m)
Re: Php Form To Mail
« #10 on: March 12, 2007, 05:52 PM »

Let's assume you know how to design your usual php form that can submit calling up any other php script,

To send to email is as basic as using codes like these:

<?php
$to = $_POST["to"];
$from = $_POST["from"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = "From: " . $from . "\r\n";

$mailsent = mail($to, $subject, $message, $headers);

if ($mailsent) {
echo "Congrats! The following message has been sent: <br><br>";
echo "<b>To:</b> $to<br>";
echo "<b>From:</b> $from<br>";
echo "<b>Subject:</b> $subject<br>";
echo "<b>Message:</b><br>";
echo $message;
} else {
echo "There was an error, ";
}
?>

to,from,subject,message being field names from your form
jozzy
Re: Php Form To Mail
« #11 on: March 15, 2007, 11:53 PM »

I use linux host. thank you very mush
oleku (m)
Re: Php Form To Mail
« #12 on: March 24, 2007, 01:27 PM »

This is a modified version  Posted by DevDel, The advantage is that it can support form with multiple fields, Name , Age, Address and send all to your email, but it has no verification or field data.

If you want the version with verification of field data please let me know.


[size=12pt]
Code:
<?php

# ===================================== #
#  This is just a little modification #
#       #
# Modified By : #
# By Oleku Konko design@oleku.org #
# ==================================== #

$p = &$_POST ; // Saves typing

$to = "empty@mydomain.com";
$subject = null ;
$from = null ;
$message = "" ;

foreach (
$p as $key => $value)
{
if($key == "subject")
$subject = $value ;

if($key == "email")
$from = $value ;

$message .= $key . " =: " . $value ;
}

$subject = ($subject == null) ? "Online Form" : $subject ;
$from = ($from == null) ? "empty@mydomain.com" : $from;


$headers = "From: " . $from . "\r\n";

if (@
mail($to, $subject, $message, $headers)) {
echo
"Congrats! The following message has been sent: <br><br>";
echo
"<b>To:</b> $to<br>";
echo
"<b>From:</b> $from<br>";
echo
"<b>Subject:</b> $subject<br>";
echo
"<b>Message:</b><br>";
echo
$p['message'];
} else {
echo
"There was an error, ";
}

?>
[/size]
 How To Write Parallel Applications For Clusters  Help On C#  Anybody Got Da Latest Oracle Dumps For Oca And Ocp?  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Job Talk Jobs/Vacancies (2) Career Talk Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.