Baniboy 3 Report post Posted December 1, 2008 (edited) Well in this month when I started transforming my unready xhtml files into php and making mail function by POST since I figured out "GET" is an insecure way of transforming information of other people. I got problem, it's in finnish but I have explained the stuff in English in the comment lines. And one more thing, I'm newbie so don't laugh too much if there is somehitng wrong with the simplest thing, please!Here's the form: <form action="skriptit/sivupalauteskripti.php" method="post"> <b>Nimi:</b> <br> <input type="text" name="nimi"> <br> <!-- This is the name input text area --> <b>Sähköposti:</b> <br> <input type="text" name="sposti"> <br> <!-- This is e-mail input --> <b>Palaute:</b> <br><textarea name="palaute"> <!-- Another text area for comments --> </textarea> <br> <input type="submit" value="Lähetä palaute"> <!-- The submit button --> </form> And the php script: <?php//I don't know how to explain this on English, you should get what this does after a few looks :D "nimi" is the name and "arvo" is value, I think something is wrong with them but I don't know what!foreach($_POST as $nimi => $arvo) { $palaute .= $nimi . ": " . $arvo . "\n";}//Send the comment to email by php "mail" function$viesti = mail("my-email@myemail.com", "Palaute", $palaute);//$viesti is true when email is sent succesfullyif($viesti) { //when sent succesfully, it redirects to the thank you page header("Location: ../kiitos.php");} else { //If not, it will redirect to the error page header("Location: ../virhe.php");}?>Edit: I would also like to know if I can do this in another way without the spam bots picking out my e-mail address Notice from truefusion: Use code bbcode, or others, for code. Edited December 1, 2008 by truefusion (see edit history) Share this post Link to post Share on other sites
xpress 0 Report post Posted December 1, 2008 You hadn't mentioned what problem you are getting. But I am assuming that you can't connect or send mails on localhost using your program. So I am correcting your mistakes as per my assumption. First of all I would like to tell you some simple basic things in this. You must have a mail server installed and the service should run in the background if you want to send mails to your localhost. If not it will give you an error that "Failed to connect localhost...." Your mail program and some names you used are quiet confusing for me.... sorry, I am changing them for my convenience... here is an easy version for your program. I'll point out the mistakes at that particular part of the code. This is your form....lets name it mailform.html <form action="mymail.php" method="post"> Enter your Name:<input type="text" name="name" /> <br />Enter your Email:<input type="text" name="email" /> <br />Enter your Message:<textarea name="message"> Enter your message here</textarea><br /><input type="submit" value="Submit" /></form> Now the php program that handles your code...lets name it processmail.php(as in form).I changed this program also to make it clear and easy to understand. <?php//you can use your foreach here but that is confusing$name=$_POST['name']; //this will receive the name$email=$_POST['email']; //this will receive the email address you mentioned$message=$_POST['message']; //receives the textarea$recipent="yourname@yourdomain.com"; //you should set this in your local smtp server...this is to in mail function$subject="user details form"; //this is subject//This is the main mistake you made I think...you must have From header in your mail funcion or you should set it in php.ini file.$header="From:$name"; //From header is must$header .= "Reply-To:$email"; //jsut adding headers$send=mail($recipent, $subject, $message, $header) or die("failure"); //recipent, subject and message are mustif($send)echo "success";?> I write this code as per my assumption of your mistake. Modify this code but follow the mail functions syntax.... First download a mail server like hMailServer(I'm using this...nice one) or someother else. And add a domain like mydomain.some and create a new mail account in that.....use that as your recipent address. If your problem is different or if you can't understand this...post your problem(or error you are getting) clearly here and I'll try to solve your problem Share this post Link to post Share on other sites
Baniboy 3 Report post Posted December 1, 2008 Thankyou xpress, you know what I do: screw everything up with something too confusing even I don't undrestand myself. I'll try a web server and create an account on there. I'll tell if it worked out fine. Thanks for the help Share this post Link to post Share on other sites
xpress 0 Report post Posted December 1, 2008 I'll try a web server and create an account on there. I'll tell if it worked out fine. Thanks for the helpYou're welcome You'll Try a webserver or mail server? Setup a mail server...(I think you already have a webserver installed) Share this post Link to post Share on other sites
Baniboy 3 Report post Posted December 1, 2008 (edited) You're welcome. You'll Try a webserver or mail server? Setup a mail server...(I think you already have a webserver installed)Not actually, which web server you suggest?For now I've just moved my php files on the net and tried them out. Edited December 1, 2008 by baniboy (see edit history) Share this post Link to post Share on other sites
xpress 0 Report post Posted December 1, 2008 For PHP......use WAMP server. It has Apache Webserver, MySql and PHP included. So no need to install all of them separately. I have been using it for some time. It is easy to install and manage. Another one is XAMPP.....but I suggest WAMP server. Download and install it. Ask me if you need any assistance setting up it... Share this post Link to post Share on other sites
Baniboy 3 Report post Posted December 3, 2008 I wonder if there is a way to get the forms directly to your normal email account, like the one in msn or yahoo or gmail etc. It would be quite handy, don't you think? Share this post Link to post Share on other sites
xpress 0 Report post Posted December 3, 2008 I didn't understand what you said. Do you mean sending mails directly from your mail account or to your mail account? Share this post Link to post Share on other sites
Baniboy 3 Report post Posted December 3, 2008 I didn't understand what you said. Do you mean sending mails directly from your mail account or to your mail account? I ment like if you have a e-mail account provided my popular service like yahoo, let's name it "myemail@yahoo.com" then with alittle programming you would have the form to be sent to your myemail@yahoo.com Share this post Link to post Share on other sites
veerumits 0 Report post Posted December 6, 2008 Dear i am here posting the information regarding sending mail from mail server to any client using php tools <?phpif(isset($_REQUEST['Submit'])){ @extract($_POST); $subject=$subject; $msg="Name:".$name."\n"."Email:".$email."\n"."Message:".$msg;$to="yourmail@yahoo.com"; $headers .= "Reply-to: $headers4\n";$headers .= "From: $email\n";$headers .= "Errors-to: $headers4\n"; if(mail("$em","Query!!!","$msg \n \n Site Admin","$headers")) { $massage1="<center><font face='Verdana' size='2' ><b>THANK YOU</b> <br>Your email has been sent successfully..</center>"; } else{ echo " <center><font face='Verdana' size='2' color=red >There is some system problem in sending login details to your address. Please contact Site Admin. <br></center></font>"; }} ?><table width="99%" border="0" align="center" cellpadding="0" cellspacing="5" bgcolor="#CCCCFF"> <form method="post" action="Contactus.php" enctype="multipart/form-data" name="form" > <tr> <td width="27%" align="right" class="form_text">Name<span class="price_text">*</span> </td> <td width="73%" align="left"><input name="name" type="text" class="form_text_area" id="name" maxlength="32" /></td> </tr> <tr> <td align="right" class="form_text">Email<span class="price_text">*</span> </td> <td align="left"><input name="email" type="text" class="form_text_area" id="email" maxlength="32" /></td> </tr> <tr> <td align="right" class="form_text">Subject<span class="price_text"> *</span></td> <td align="left"><input name="subject" type="text" class="form_text_area" id="subject" maxlength="32" /> </td> </tr> <tr> <td align="right" class="form_text">Message<span class="price_text"> *</span></td> <td align="left"><label> <textarea name="msg" cols="30" rows="10" id="msg"></textarea> </label></td> </tr> <tr> <td align="right" class="form_text"> </td> <td align="left"><label> <input type="submit" name="Submit" value="Submit" /> </label></td> </tr></form></table> if still have any question in this topic please reply.thanks I ment like if you have a e-mail account provided my popular service like yahoo, let's name it "myemail@yahoo.com" then with alittle programming you would have the form to be sent to your myemail@yahoo.com Share this post Link to post Share on other sites
iGuest 3 Report post Posted February 18, 2010 request for send attachment mail using php with html codePhp Mail Function Not Working!I have write send attachment mail using html with php code . This is not send . Please reply me.The code is as follows <?php // request variables // important$from=$_REQUEST["from"];$emaila=$_REQUEST["emaila"];$filea=$_REQUEST["filea"]; if ($filea){ function mail_attachment ($from , $to, $subject, $message, $attachment){ $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $email_from = $from; // Who the email is from $subject = "New Attachment Message"; $email_subject = $subject; // The Subject of the email $email_txt = $message; // Message that the email has in it $email_to = $to; // Who the email is to $headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $msg_txt="andand You have recieved a new attachment message from $from"; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "nMIME-Version: 1.0and" . "Content-Type: multipart/mixed;and" . " boundary="{$mime_boundary}""; $email_txt .= $msg_txt; $email_message .= "This is a multi-part message in MIME format.andand" . "--{$mime_boundary}and" . "Content-Type:text/html; charset="iso-8859-1"and" . "Content-Transfer-Encoding: 7bitandand" . $email_txt . "andand"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}and" . "Content-Type: {$fileatt_type};and" . " name="{$fileatt_name}"and" . //"Content-Disposition: attachment;and" . //" filename="{$fileatt_name}"and" . "Content-Transfer-Encoding: base64andand" . $data . "andand" . "--{$mime_boundary}--and"; $ok = mail($email_to, $email_subject, $email_message, $headers); if($ok) { header("Location:index.Html"); echo "File Sent Successfully."; unlink($attachment); // delete a file after attachment sent. } else { echo "not send"; die("Sorry but the email could not be sent. Please go back and try again!"); }} move_uploaded_file($_FILES["filea"]["tmp_name"],'temp/'.Basename($_FILES['filea']['name']));Mail_attachment("$from", "ulaganathan.Kmca@gmail.Com", "subject", "message", ("temp/".$_FILES["filea"]["name"]));}?> <html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title> <script language="javascript" type="text/javascript">Function CheckData45(){ with(document.Filepost){ if(filea.Value != ""){Document.GetElementById('one').InnerText = "Attaching File ... Please Wait";}}}</script> </head> <body> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="top"> <form name="filepost" method="post" action="file.Php" enctype="multipart/form-data" id="file"> <table width="300" border="0" cellspacing="0" cellpadding="0"> <tr valign="bottom"> <td height="20">Your Name:</td> </tr> <tr> <td><input name="from" type="text" id="from" size="30"></td> </tr> <tr valign="bottom"> <td height="20">Your Email Address:</td> </tr> <tr> <td class="frmtxt2"><input name="emaila" type="text" id="emaila" size="30"></td> </tr> <tr> <td height="20" valign="bottom">RFQ File:</td> </tr> <tr valign="bottom"> <td valign="bottom"><input name="filea" type="file" id="filea" size="16"></td> </tr> <tr> <td height="40" valign="middle"><input name="Reset2" type="reset" id="Reset2" value="Reset"> <input name="Submit2" type="submit" value="Submit" onClick="return CheckData45()"></td> </tr> </table> </form> <center><table width="400"><tr><td id="one"></td></tr></table></center> </td> </tr></table></body></html> -question by Ulaganathan.K Share this post Link to post Share on other sites