Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,407 members, 7,843,205 topics. Date: Tuesday, 28 May 2024 at 08:33 PM

Php Form To Mail - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Php Form To Mail (1637 Views)

Connecting Vb.net 2010 window Form To Sql Server Online / How Do I Connect A Form To Mysql Database / Php Form To Mail Problem (2) (3) (4)

(1) (Reply) (Go Down)

Php Form To Mail by jozzy: 1:58pm On Feb 05, 2007
Can any one help me out how can i get php form to email  script
Re: Php Form To Mail by kengimel(m): 11:00am On Feb 06, 2007
Well i think this will help you http://formtoemail.com/
Re: Php Form To Mail by jozzy: 11:43am On Feb 06, 2007
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
Re: Php Form To Mail by alexis(m): 9:21pm On Feb 06, 2007
tell the fields you want to use so that I can guide you how to build one
Re: Php Form To Mail by jozzy: 2:40am On Feb 07, 2007
Thank for your reply, this is my code from the form when my feedback page is tag[b] fback.php[/b], 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>
Re: Php Form To Mail by xanadu: 3:05am On Feb 10, 2007
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'.

<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:

<?
//===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==""wink {
  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==""wink {
  echo "<p><center><font color='red'>Please enter your last name</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

elseif ($chapter==""wink {
  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"wink {
  echo "<p><center><center><font color='red'>Please select a zone</font>"; 
  echo "<p><a href='javascript:history.back(1);'>Back</a>";
}

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

elseif ($comment==""wink {
  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"wink;


//===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.
Re: Php Form To Mail by jozzy: 5:06am On Feb 13, 2007
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 pls do put me through
Re: Php Form To Mail by xanadu: 12:49pm On Feb 14, 2007
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?
Re: Php Form To Mail by iilenloa(m): 11:37am On Feb 23, 2007
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;


<?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.
Re: Php Form To Mail by DevDel(m): 5:51pm On Mar 12, 2007
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
Re: Php Form To Mail by DevDel(m): 5:52pm On Mar 12, 2007
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
Re: Php Form To Mail by jozzy: 11:53pm On Mar 15, 2007
I use linux host. thank you very mush
Re: Php Form To Mail by oleku(m): 1:27pm On Mar 24, 2007
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.


<?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"wink
$subject = $value ;

if($key == "email"wink
$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, ";
}

?>

(1) (Reply)

Serious Advice Needed / Please Rate This Light Weight Pc Software I Developed (getgist). / Need Someone That Can Write Php Marketing Script.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 77
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.