PHP - Php Mail Form
Similar Tutorialssystem: vista ultimate sp2 IIS 7 server installed and running PHP 5 fastCGI im not sure if this is within the purview of the forum but you all seem like smart people with an expertise in this area. i have a web site http://penumbraproductions.dyndns-remote.com/ . it is hosted locally on my desktop using the above mentioned IIS7 server options using dyndns to list the url cause my ISP has DHCP without static ip's for non-business accounts that has a contact form... form mail. i've tried numerous php codes to get it to send mail to my email account but none of them are working my IIS smtp setting a email to: archaismic@gmail.com smtp server: smtp.gmail.com port number: 465 using login credentials i've also tried to configuring the smtp options in IIS to dump the mail to a folder on my computer which also did not work attached is the feedback.php file im currently working with minus the captcha private key and the code for the form i'm using is: Code: [Select] <form action="feedback.php" method="post"> <table border="0" cellpadding="8" cellspacing="8"> <tr><td><label for="tswname">Name</label>:</td><td><input type="text" name="fullname" id="tswname" size="25" /></td></tr> <tr><td><label for="tswemail">Email address</label>:</td><td><input type="text" id="tswemail" name="email" size="25" /></td></tr> <tr> <td colspan="2"> <label for="tswcomments">Comments</label><br /> <textarea rows="15" cols="45" name="comments" id="tswcomments"></textarea> </td> </tr> <tr> <td align="center" colspan="2"> <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LcYjcASAAAAAH1NwZ0IH_TUO4XDANZqWu3Ei9yh"></script> <noscript> <iframe src="http://api.recaptcha.net/noscript?k=6LcYjcASAAAAAH1NwZ0IH_TUO4XDANZqWu3Ei9yh" height="300" width="500" frameborder="0" title="CAPTCHA test"></iframe> <br /> <label for="tswcaptcha">Copy and paste the code provided in above box he </label><br /> <textarea name="recaptcha_challenge_field" id="tswcaptcha" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge" /> </noscript> </td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="Send Feedback" /> </td> </tr> </table> </form> I have a notification system that notifies users of new comments, inside the email I have images, some of the logo, some of different people, everything shows up fine on my computer (yahoo email), however in the iPhones email application no images show up, there are just the blue squares with the question marks in them. I'm not sure what I'm missing. Code: [Select] $from = "Kithell <notifications@kithell.com>"; $headers = "From:" . $from ."\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $subject = name($from_id, 'fl').$action; $message = '<html><body> <style>@charset "utf-8"; /* CSS Document */ .e-container { background-color: #FFF;position: relative;width: 90%;min-height:1px;margin-right: auto;margin-left: auto; } .e-container .e-m-header { padding: 2px; background-image: url(http://www.kithell.com/assets/tall-grey-header.png); background-repeat: repeat-x; border: 1px solid #CCC; background-position: bottom; display: block; text-align: center; } .e-container p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #666; vertical-align: text-top; display: inline-block; } .e-container .e-usr-photo { display: inline-block; margin: 10px; float: left; background-color: #F4F4F4; } .e-container p a { font-weight: bold; color: #3F60A3; text-decoration: underline; padding: 0px; float: left; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px; } .e-container .e-quotes { font-size: 20px; font-weight: bold; color: #999; font-family: Tahoma, Geneva, sans-serif; display: block; padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 75px; margin-top:10px; } .e-container .e-message { font-size: 13px; color: #333; padding: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 10px; clear: none; display: inline; }</style> <div class="e-container"><div class="e-m-header"><img src="http://www.kithell.com/assets/kithell-logo.png" /></div><img class="e-usr-photo" src="http://www.kithell.com/'.photo($from_id, 55).'" /><br /><p><a target="_blank" href="http://www.kithell.com/#/profile&id='.$from_id.'">'.name($from_id, "fl").' </a> '.$action.'<div class="e-quotes">"<p class="e-message">'.nl2br(htmlentities(stripslashes($message))).'</p>"</div></p></div></body></html>'; mail($to,$subject,$message,$headers); This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 I have this in a file called mailform.php. It check for valid email and phone number. If wrong it echo error but it still send the mail to me. I need for it if error not to send then redirect to same page with problems. no error redirect to main page. I can get to redirect with no problem. I can't figure out how to make it not send if errors. I hope I am explaining this right. Code: [Select] $fname = $_POST['firstName']; $lname = $_POST['lastName']; $degree = $_POST['Degree_Certificate']; $company = $_POST['companyName']; $address = $_POST['street']; $city = $_POST['city']; $state = $_POST['stateProvReg']; $phone = $_POST['phone']; $email = $_POST['email']; $message = $_POST['description']; $receive = "we receive your Affiliate information"; $formcontent=" Thank you $receive \n First Name: $fname \n Last Name: $lname \n Degree: $degree \n Company: $company \n Address: $address \n City: $city \n State: $state \n Phone: $phone \n Email: $email \n Description: $message"; $recipient = "webtechnician@brainmaster.com, $email"; $subject = "Affiliate List"; $mailheader = "From: $email \r\n"; if (validatePhone($phone)) { echo $phone . ' is a valid phone number.'; } else { echo $phone . ' is not valid phone number.'; } if (check_email_address($email)) { echo $email . ' is a valid email address.'; } else { echo $email . ' is not a valid email address, please hit the back button.'; } function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; die("hit the back button"); } } } return true; } function validatePhone($phone) { $numbersOnly = ereg_replace("[^0-9]", "", $string); $numberOfDigits = strlen($numbersOnly); if ($numberOfDigits == 7 or $numberOfDigits == 10) { echo $numbersOnly; } else { echo 'Invalid Phone Number'; } } function valIP($string) { if (preg_match( '^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$^', $string)) { echo $string; } else { echo 'Invalid IP Address'; } } mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!"; header('Location: http://#'); Hey everyone. I am extremely new to PHP coding and I wanted to take a shot at making a basic mail form submission. I have done a lot of research and cannot get my test files to work. No e-mails get sent to me. I appreciate any help you can offer. Here are the following pages: http://www.insightguild.com/contactformpage.html http://www.insightguild.com/sendmail.php (coding is viewable when you navigate to this file) I am using Bluehost.com as my hosting server. Thanks I have a pretty good php mailer script, but how do I get the senders email? When I test the form, the users email doesn't appear in the "From" field. Anyone know what I need to add to my code? Thanks. <?php if (array_key_exists('send', $_POST)) { // mail processing script // remove escape characters from POST array if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } $from = 'Emailer Form'; $to = 'myEmail.com'; $subject = 'Interested in Urban Style Ballroom Dancing'; // list expected fields $expected = array('name', 'phone', 'email', 'address', 'city', 'state', 'zip', 'emailerMessage'); // set required fields $required = array('name', 'phone', 'email', 'address', 'city', 'state', 'zip', 'emailerMessage'); // create empty array for any missing fields $missing = array(); // process the $_POST variables foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } // otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } // go ahead only if all required fields OK if (empty($missing)) { // build the message $message = "name: $name\n\n"; $message .= "phone: $phone\n\n"; $message .= "email: $email\n\n"; $message .= "address: $address\n\n"; $message .= "city: $city\n\n"; $message .= "state: $state\n\n"; $message .= "zip: $zip\n\n"; $message .= "emailerMessage: $emailerMessage\n\n"; // limit line length to 70 characters $message = wordwrap($message, 70); // send it $mailSent = mail($to, $subject, $message); if ($mailSent) { // $missing is no longer needed if the email is sent, so unset it unset($missing); } } } ?> Okay, really dumb question... If I want to make an HTML Form that is really an E-mail Form so that visitors on my website can e-mail me, how do I do that? (I had read in a book last year that if you use an HTML Form, you can reduce/eliminate spam?!) Debbie Hello all, Just started learning a bit of PHP from resources i can find over the net. I am working on a mail form and it works perfectly with the english text. no errors or issues. But when i type in arabic my outlook receives it as : فات ثيات سثسقغتن غتن فغثتن ثغ ثغن صف يفغن فغ ن صفغن ثعغ صتنفغت صنثفع Could anyone point out where my problem is please ? Thanks in advance and appreciate yoru help guys. Cheers. HTML - test.html Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Form</title> <link href="style_form.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" name="form1" method="post" action="test.php"> <table width="830" border="0" cellspacing="0" cellpadding="5"> <tr> <td height="78" colspan="2" valign="top" background="images/fheader.jpg"><p> </p> <p> </p></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid; border-top: 8px white solid;"><strong>Name: *</strong></td> <td style="border-bottom: 2px white solid; border-top: 8px white solid;"><textarea name="name" cols="58" rows="1" id="name"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Occupation: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="occupation" id="occupation" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Nationality: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="nationality" cols="58" rows="1" id="nationality"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Country of residence: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="country" id="country" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Telephone number: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="telephone" id="telephone" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Email address: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="email" id="email" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Comments:</strong> *</td> <td style="border-bottom: 2px white solid;"><textarea name="j" id="j" cols="58" rows="4"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Comments about us: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="jd" id="jd" cols="58" rows="4"></textarea></td> </tr> <tr > <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Comments about the website: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="website" id="website" cols="58" rows="4"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Other information you wish to provide:</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="other" id="other" cols="58" rows="4"></textarea></td> </tr> <tr> <td valign="top"> </td> <td><input type="submit" name="Submit" id="Submit" value="Submit" /> <input type="submit" name="Reset" id="Reset" value="Reset" /></td> </tr> </table> </form> </body> </html> PHP - test.php <?php if(isset($_POST['Submit'])) { $to = "email@email.com"; $subject = "Feedback [Arabic]"; $name_field = $_POST['name']; $occupation_field = $_POST['occupation']; $nationality_field = $_POST['nationality']; $country_field = $_POST['country']; $telephone_field = $_POST['telephone']; $email_field = $_POST['email']; $j_field = $_POST['j']; $jd_field = $_POST['jd']; $website_field = $_POST['website']; $other_field = $_POST['other']; $headers = "MIME-Version: 1.0 \n" ; $headers .= "Content-Type: text/plain;charset=UTF-8 \n"; $body = mb_convert_encoding($body, "UTF-8","AUTO"); mb_language("uni"); $body = "Name: $name_field\n\n Occupation: $occupation_field\n\n Nationality: $nationality_field\n\n Country of residence: $country_field\n\n Telephone: $telephone_field\n\n Email: $email_field\n\n Comments: $j_field\n\n Comments about us: $jd_field\n\n Comments about website: $website_field\n\n Other information: $other_field\n\n"; mb_send_mail($to, $subject, $body); } else { echo "error: no data sent!"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Sending...</title> <meta http-equiv="refresh" content="1;url=fthankyou_ar.html"> <meta http-equi </head> <div align="center"> <p><img src="/images/loadbar.gif" width="232" height="11"></p> <p><b>Prcessing and redirecting ...</b></p> </div> </body> </html> I have this code as my session_init.php Code: [Select] <?php $_SESSION['APP_MX'] = "mail.mywebsite.com"; $_SESSION['APP_SERVER'] = "mywebsite.com"; $_SESSION['SITE_EMAIL'] = "admin@mywebsite.com"; $_SESSION['MYSQL_SERVER1'] = "localhost"; $_SESSION['MYSQL_LOGIN1'] = "root"; $_SESSION['MYSQL_PASS1'] = "password"; $_SESSION['MYSQL_DB1'] = "sample"; $_SESSION['LOGGEDIN'] = ""; $_SESSION['USERID'] = 0; $_SESSION['EMAIL'] = ""; $_SESSION['FNAME'] = ""; $_SESSION['LNAME'] = ""; $_SESSION['SESSION'] = true; ?> and I'm calling it here Code: [Select] <?php if(!isset($_SESSION['SESSION'])) require('../email/session_init.php'); $fname = $_POST["fname"]; $lname = $_POST["lname"]; $email= $_POST["email"]; $company = $_POST["company"]; $subject = $_POST["subject"]; $phone = $_POST["phone"]; $msg = $_POST["msg"]; $mail = "Hello $fname,\n\nThank your for your email.\nWe look forward to your evaluation of our product.\n\n"; $mail .= "Here is the information you have given us:\n\n"; $mail .= "Name: ".$fname." ".$lname."\n"; $mail .= "Company: ".$company."\n"; $mail .= "Email Address: ".$email."\n"; $mail .= "Phone: ".$phone."\n\n"; $mail .= "Subject: ".$subject."\n"; $mail .= "Your Message:\n".$msg."\n\n\n"; $mail .= "Best Regards,\nCustomer Service\n\n"; // If any lines are larger than 70 characters, we will use wordwrap() $message = wordwrap($msg, 70); mail($email, $subject, $mail, "From: admin@".$_SESSION['APP_SERVER']."\r\n"); $mail = str_replace("\n", "<br>", $mail); ?> And I'm getting this error Quote Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 26, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\php\website_interactivity\email\email_sent.php on line 33 I wonder if there's any modification that I need to do in my php.ini file. Anyone? Hi, I have a (rather long) form on my site that when submitted send the information to me in an email. Ideally I would like to have the form only send me the information that has been filled out at current it sends everything. but for now I just need to know how I can style the email so its not one long list. also the form only comes through if an email adress is filled in it says it sends but I never recieve it. heres an example of the code for sending the email $Date = Trim(stripslashes($_POST['Date'])); $Packing = Trim(stripslashes($_POST['Packing'])); $Dismantle = Trim(stripslashes($_POST['Dismantle'])); $DismantleYes = Trim(stripslashes($_POST['DismantleYes'])); $Plumbing = Trim(stripslashes($_POST['Plumbing'])); $PlumbingYes = Trim(stripslashes($_POST['PlumbingYes'])); $LRSofa = Trim(stripslashes($_POST['LRSofa'])); $LRArmChair = Trim(stripslashes($_POST['LRArmChair'])); $LROtherChair = Trim(stripslashes($_POST['LROtherChair'])); $LRSCabinet = Trim(stripslashes($_POST['LRSCabinet'])); $LRLCabinet = Trim(stripslashes($_POST['LRLCabinet'])); $LRBookcase = Trim(stripslashes($_POST['LRBookcase'])); $LROTable = Trim(stripslashes($_POST['LROTable'])); $LRCTable = Trim(stripslashes($_POST['LRCTable'])); $LRTVStand = Trim(stripslashes($_POST['LRTVStand'])); $Body .= "Date of move: "; $Body .= $Date; $Body .= "\n"; $Body .= "Packing: "; $Body .= $Packing; $Body .= "\n"; $Body .= "Dismantle: "; $Body .= $Dismantle; $Body .= "\n"; $Body .= $DismantleYes; $Body .= "\n"; $Body .= "Plumbing: "; $Body .= $Plumbing; $Body .= "\n"; $Body .= $PlumbingYes; $Body .= "\n"; $Body .= "\n"; $Body .= "Living Room: "; $Body .= "\n"; $Body .= "Sofas: "; $Body .= $LRSofa; $Body .= "\n"; $Body .= "Arm Chairs: "; $Body .= $LRArmChair; $Body .= "\n"; $Body .= "Other Chairs: "; $Body .= $LROtherChair; $Body .= "\n"; $Body .= "Small Cabinets: "; $Body .= $LRSCabinet; $Body .= "\n"; $Body .= "Large Cabinets: "; $Body .= $LRLCabinet; $Body .= "\n"; $Body .= "Bookcases: "; $Body .= $LRBookcase; $Body .= "\n"; $Body .= "Occassional Tables: "; $Body .= $LROTable; $Body .= "\n"; $Body .= "Coffee Tables: "; $Body .= $LRCTable; $Body .= "\n"; $Body .= "TV Stand: "; // send email $success = mail($EmailTo, $Subject, $Body, "From: ". $FName ." ". $LName ." <". $Email.">"); // redirect to success page if ($success){ header ('Location: thankyou.php'); } else{ header ('Location: error.php'); } I am trying to send the data entered in to the form to myself and to the user. At the moment I am getting the data sent to myself but cant find the way to send it to the user. I am using this code below <?php mail("webmaster@edgwaretown.co.uk", $subject, $message, $from); ?> How can I get the user to get the data by email as well? Thanks Gary I have not been able to get my mail form to send messages to my email. The thank you page pops up after I test it, but nothing is sent. I use GoDaddy, so I'm not sure if that is part of the problem. This is my first attempt at PHP, so I don't know what I'm doing! I got the code from the Site Wizard. Any help would be great! Here is the code in my HTLM page for the form: <div id="package"> <fieldset id="personalinfo"> <legend class="perlegend"><img src="Art/header_contact.png" class="perlegendheader" > <div id="collage"></div> </legend> <p> </p> <form action="gdform.php" method="post"> <input type="hidden" name="redirect" value="thankyou.html" /> <p> <label for="name"> Name</label> <br> <input name="name" type="text"/> </p> <p> <label for="email">Email</label> <span class="required">(required)</span><br> <input name="email" type="text"/> </p> <p> <label class="top" for="comments">Message</label> <br> <textarea name="comments" cols="32" rows="5"></textarea> </p> <p> <input name="Submit" type="submit" class="submit" value="SEND"/> </p> </form> <br class="clear" /> </p> </fieldset > <br> </div> Here is my PHP code (without my real email address): <?php // ------------- CONFIGURABLE SECTION ------------------------ $mailto = 'XXX@gmail.com' ; $subject = "Message from Martha Berry Design" ; $formurl = "http://www.marthaberrydesign.com/contact.html" ; $errorurl = "http://www.marthaberrydesign.com/error.html" ; $thankyouurl = "http://www.marthaberrydesign.com/thankyou.html" ; $email_is_required = 1; $name_is_required = 0; $comments_is_required = 0; $uself = 0; $use_envsender = 0; $use_sendmailfrom = 1; $use_webmaster_email_for_from = 0; $use_utf8 = 1; $my_recaptcha_private_key = '' ; // -------------------- END OF CONFIGURABLE SECTION --------------- $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ; if (!isset( $use_envsender )) { $use_envsender = 0 ; } if (isset( $use_sendmailfrom ) && $use_sendmailfrom) { ini_set( 'sendmail_from', $mailto ); } $envsender = "-f$mailto" ; $fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($comments_is_required && empty($comments))) { header( "Location: $errorurl" ); exit ; } if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) { header( "Location: $errorurl" ); exit ; } if (strlen( $my_recaptcha_private_key )) { require_once( 'recaptchalib.php' ); $resp = recaptcha_check_answer ( $my_recaptcha_private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); if (!$resp->is_valid) { header( "Location: $errorurl" ); exit ; } } if (empty($email)) { $email = $mailto ; } $fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ; if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } $messageproper = "This message was sent from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "Name of sender: $fullname\n" . "Email of sender: $email\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; $headers = "From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" . $headersep . 'MIME-Version: 1.0' . $headersep . $content_type ; if ($use_envsender) { mail($mailto, $subject, $messageproper, $headers, $envsender ); } else { mail($mailto, $subject, $messageproper, $headers ); } header( "Location: $thankyouurl" ); exit ; ?> I need this form to be sent to a mail after you press the button and to see the content that is sent , what is the easiest way to do this? http://fhcs.be/ Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions session_start(); $dranken=array(); $DrinkResult=mysql_query("SELECT name,price FROM products" )or die(mysql_error()); while($DrinkRow=mysql_fetch_assoc($DrinkResult)) { $dranken[]=$DrinkRow; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head></head> <body> <?php if (!isset($_POST['submit'])) { ?> <form method="post" action="mail.php"> <input type="submit" value="Toon Output" name="submit"/> <?php echo "<table>"; foreach ($dranken as $DrinkRow) { $optionlist = "<select name='{$DrinkRow['name']}_aantal'>"; for($i=0;$i<10;++$i) { $optionlist .= "<option value='$i'>$i</option>"; } $optionlist .= "</select>"; echo "<tr><td>". $DrinkRow['name']."</td><td>".$DrinkRow['price']."</td>"; echo "<td>$optionlist</td></tr>"; } echo "</table>"; ?> </form> <?php } else { echo "<table>"; $totaalPrijs = 0; foreach ($dranken as $DrinkRow) { $aantal = $_POST[ $DrinkRow['name'] . "_aantal"]; if ($aantal > 0) { $prijsperDrank = $aantal * $DrinkRow['price']; echo $DrinkRow['name'] . " : " . $aantal . " Prijs: " . $prijsperDrank . "</br>"; $totaalPrijs=$totaalPrijs + $prijsperDrank; } } if($totaalPrijs>0) { echo " totaal: " .$totaalPrijs; } echo "</table>"; } ?> </body> </html> Hi
I'm a beginner in php and are facing a problem i cant seem to find the correct solution on. $item5 = $_POST['PIGM1']; if (empty($item5)) { $email_body .= ''; } if (isset($item5)) { $email_body = '<html><head><style type="text/css">td { width: 450; }</style></head><body>'; $email_body .= '<table border="0" width="900">'; $email_body .= '<tr><td><strong>Header in table</strong></td><td></td></tr>'; $email_body .= '<tr><td><strong>Ordered</strong></td><td>' . $item5 . ' pcs. of some item</td></tr>'; $email_body .= '</table><br />'; } Can anyone help me in the right direction? HI recently we have been starting to recieved about 30 spam emails aday. I read that the issue was how my forms were submitting and that it kept bypassing the javascript. I found some code i could use at http://chrisplaneta....with_recaptcha/ but i cannot seem to get the form to function correctly.
It is supposed to email me once the form is validated but the email does not seem to be sending.
Also i would like the form to redirect to a thank you page once it has been agreed. I did try but it kept telling me the headers had already been called. i am calling the page in with php include. Can you please advise the best way for me to relocate.
I have attached a copy of my form.php page which has every thing on. I have also included the code at the bottom of this email
Also i would appreciate any comments on what i can include on my form to limit the spammers
<?php //If the form is submitted: if(isset($_POST['submitted'])) { //load recaptcha file require_once('captcha/recaptchalib.php'); //enter your recaptcha private key $privatekey = "6Ld5Df4SAAAAAKciqwDco8dfvBR15fGeFVXWcvCO"; //check recaptcha fields $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); //Check to see if the invisible field has been filled in if(trim($_POST['checking']) !== '') { $blindError = true; } else { //Check to make sure that a contact name has been entered $authorName = (filter_var($_POST['formAuthor'], FILTER_SANITIZE_STRING)); if ($authorName == ""){ $authorError = true; $hasError = true; }else{ $formAuthor = $authorName; }; //Check to make sure sure that a valid email address is submitted $authorEmail = (filter_var($_POST['formEmail'], FILTER_SANITIZE_EMAIL)); if (!(filter_var($authorEmail, FILTER_VALIDATE_EMAIL))){ $emailError = true; $hasError = true; } else{ $formEmail = $authorEmail; }; //Check to make sure the subject of the message has been entered $msgSubject = (filter_var($_POST['formSubject'], FILTER_SANITIZE_STRING)); if ($msgSubject == ""){ $subjectError = true; $hasError = true; }else{ $formSubject = $msgSubject; }; //Check to make sure content has been entered $msgContent = (filter_var($_POST['formContent'], FILTER_SANITIZE_STRING)); if ($msgContent == ""){ $commentError = true; $hasError = true; }else{ $formContent = $msgContent; }; // if all the fields have been entered correctly and there are no recaptcha errors build an email message if (($resp->is_valid) && (!isset($hasError))) { $emailTo = 'carlycyber@hotmail.co.uk'; // here you must enter the email address you want the email sent to $subject = 'A new message from: immigration solicitors Manchester' ; $body = "Name :formAuthor \n\nEmail: $formEmail \n\nTelephone :formSubject \n\nContent: $formContent \n\n$formAuthor"; // This is the body of the email $headers = 'From: <'.$formEmail.'>' . "\r\n" . 'Reply-To: ' . $formEmail . "\r\n" . 'Return-Path: ' . $formEmail; // Email headers // Email headers //send email mail($emailTo, $subject, $body, $headers); // set a variable that confirms that an email has been sent $emailSent = true; } // if there are errors in captcha fields set an error variable if (!($resp->is_valid)){ $captchaErrorMsg = true; } } } ?> <?php // if the page the variable "email sent" is set to true show confirmation instead of the form ?> <?php if(isset($emailSent) && $emailSent == true) { ?> <?php $message = "Thank you. Your form has been submitted and a member of our team will contact you shortly.This website is developed for generating immigration enquiries in your area and it is not a law firm, your enquiries will be passed on to a solicitor.We confirm that this website does not belong to a law firm and we have no physical office in your county. Our solicitors are able to provide immigration services all over the UK because they provide a Virtual Service.Responses to your legal enquiries and the legal opinion given to you would be provided by a qualified UK Immigration Solicitor. If you decide to proceed with the solicitor, your matter will be dealt with under a Law firm regulated by the Solicitors Regulatory Authority."; echo "<script type='text/javascript'>alert('$message');</script>"; /*echo "<script language='javascript'> window.location('http://www.immigrationsolicitorsmanchesteruk.co.uk/thankyou.php') </script>";*/ ?> <p>Thank you. Your form has been submitted and a member of our team will contact you shortly.This website is developed for generating immigration enquiries in your area and it is not a law firm, your enquiries will be passed on to a solicitor.We confirm that this website does not belong to a law firm and we have no physical office in your county. </p> <?php } else { ?> <?php // if there are errors in the form show a message ?> <?php if(isset($hasError) || isset($blindError)) { ?> <p><strong>Im sorry. There was an error submitting the form. Please check all the marked fields and try again.</strong></p> <?php } ?> <?php // if there are recaptcha errors show a message ?> <?php if ($captchaErrorMsg){ ?> <p><strong>The recaptcha was not entered correctly. Please try again.</strong></p> <?php } ?> <?php // here, you set what the recaptcha module should look like // possible options: red, white, blackglass and clean // more infor on customisation can be found he http://code.google.com/intl/pl-PL/apis/recaptcha/docs/customization.html ?> <script type="text/javascript"> var RecaptchaOptions = { theme : 'blackglass' }; </script> <?php // this is where the form starts // action attribute should contain url of the page with this form // more on that you can read he http://www.w3schools.com/TAGS/att_form_action.asp ?> <form id="contactForm" action="" method="post"> <p> <strong>Full Name</strong><br/> <input class="requiredField <?php if($authorError) { echo 'formError'; } ?>" type="text" name="formAuthor" id="formAuthor" value="<?php if(isset($_POST['formAuthor'])) echo $_POST['formAuthor'];?>"size="25" /></p> <p> <strong>Email </strong><br/> <input class="requiredField <?php if($emailError) { echo 'formError'; } ?>" type="text" name="formEmail" id="formEmail" value="<?php if(isset($_POST['formEmail'])) echo $_POST['formEmail'];?>" size="25" /> </p> <p> <strong>Telephone </strong><br/> <input class="requiredField <?php if($subjectError) { echo 'formError'; } ?>" type="text" name="formSubject" id="formSubject" value="<?php if(isset($_POST['formSubject'])) echo $_POST['formSubject'];?>" size="25" /> </p> <p> <strong>Please give us some information about your enquiry</strong><br/> <textarea class="requiredField <?php if($commentError) { echo 'formError'; } ?>" id="formContent" name="formContent" cols="25" rows="5"><?php if(isset($_POST['formContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['formContent']); } else { echo $_POST['formContent']; } } ?></textarea></p> <?php // this field is visible only to robots and screenreaders // if it is filled in it means that a human hasn't submitted this form thus it will be rejected ?> <div id="screenReader"> <label for="checking"> If you want to submit this form, do not enter anything in this field </label> <input type="text" name="checking" id="checking" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" /> </div> </div> <?php // load recaptcha file require_once('captcha/recaptchalib.php'); // enter your public key $publickey = "6Ld5Df4SAAAAANFKozja9bUlDziJ92c31DDt1j6k"; // display recaptcha test fields echo recaptcha_get_html($publickey); ?> <input type="hidden" name="submitted" id="submitted" value="true" /> <?php // submit button ?> <input type="submit" value="Send Message" tabindex="5" id="submit" name="submit"> </form> <?php } // yay! that's all folks! ?>Attached Files form issue.txt 7.58KB 1 downloads Just a bit of background first: I have a contact form set up on one of my domains. It hasn't been updated in 7 years and recently I started getting about 3-8 spam messages daily through it. At some point I updated other sites with code that includes a CAPTCHA.
Out of sheer laziness, instead of recoding the contact form that was getting spammed, I just copied & pasted one of the updated forms and changed the necessary details like which e-mail address, URL, etc. Unfortunately, this hasn’t worked out properly.
For some reason the CAPTCHA image isn’t being displayed. I keep looking but can't find the error(s). Could someone please take a look at the code and tell me what went wrong? I’d be ever so grateful for any help! The code for the form itself: <form method="post" action="mail-e.php"> <p><input type="text" name="name" id="name" value="who are you?" size="25" /></p> <p><input type="text" name="email" id="email" value="you@whatever.bla" size="25" /></p> <p><input type="text" name="url" id="url" value="http://" size="25" /></p> <p><textarea name="comments" id="comments" rows="1" cols="20">Go on, then. Tell me a story, wingy!</textarea></p> <p><img src="http://echoing.org/captcha.php" alt="humanity check" /><br /> <input type="text" name="captcha" id="captcha" /> <br /> <p><input type="submit" name="submit" id="submit" value="sing to me" /> <input type="reset" name="reset" id="reset" value="out of key" /></p> </form>mail-e.php: <?php session_start(); //Encrypt the posted code field and then compare with the stored key if(md5($_POST['captcha']) != $_SESSION['key']) { die("Error: You must enter the code correctly"); }else{ echo 'You entered the code correctly'; } ?> <?php if (!isset($_POST['submit'])) { include('./header.php'); echo "<h1>HEY!!! You just encountered an error!</h1>\n <p>You don't belong here. <strong>Because it's <em>wrong</em>.</strong> Go back and try again, please.</p>"; include('./footer.php'); exit; } function cleanUp($data) { $data = strip_tags($data); $data = trim(htmlentities($data)); return $data; } $name = cleanUp($_POST['name']); $email = cleanUp($_POST['email']); $url = cleanUp($_POST['url']); $comments = cleanUp($_POST['comments']); if ((empty($name)) || (empty($email)) || (empty($comments))) { include('./header.php'); echo "<h2>Input Error! Looks like you missed some stuff.</h2>\n <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>"; echo "<form action=\"mail-e.php\" method=\"post\"><p>"; echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />"; echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />"; echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />"; echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />"; echo "<img src=\"http://echoing.org/captcha.php\" alt=\"humanity check\" style=\"margin-bottom: 2px;\" /><br />"; echo "<input type=\"text\" name=\"captcha\" id=\"captcha\" /> <br />"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />"; echo "</p></form>"; include('./footer.php'); exit; } if (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",$email)) { include('./header.php'); echo "<h2>Input Error</h2>\n <p>That e-mail address you entered - \"$email\" - is <em>not</em> a valid electronic address. Please edit it and send it in again, please:</p>"; echo "<form action=\"mail-e.php\" method=\"post\"><p>"; echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />"; echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />"; echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />"; echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />"; echo "<img src=\"captcha.php\" alt=\"humanity check\" style=\"margin-bottom: 2px;\" /><br />"; echo "<input type=\"text\" name=\"captcha\" id=\"captcha\" /> <br />"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />"; echo "</p></form>"; include('./footer.php'); exit; } $email = preg_replace("([\r\n])", "", $email); $find = "/(content-type|bcc:|cc:)/i"; if (preg_match($find, $name) || preg_match($find, $email) || preg_match($find, $url) || preg_match($find, $comments)) { include('./header.php'); echo "<h1>Error</h1>\n <p>No meta/header injections, please.</p>"; include('./footer.php'); exit; } $recipient = "my email address is here"; $subject = "paint me a wish on a velvet sky"; $message = "Name: $name \n"; $message .= "E-mail: $email \n"; $message .= "URL: $url \n"; $message .= "Comments: $comments"; $headers = "From: a wish painted on the velvet sky \r\n"; $headers .= "Reply-To: $email"; if (mail($recipient,$subject,$message,$headers)) { include('./header.php'); echo "<<p>WOO HOO! Your message was successfully sent to me! I'll read it as soon as I can. I may even respond! Thanks for using the form, fruitcake :)</p>"; include('./footer.php'); } else { include('./header.php'); echo "<p>Something went awry. Your message didn't go through. Want to take another crack at it? Please do, I'd love to hear from you!</p>"; include('./footer.php'); } ?>captcha.php: <?php //Start the session so we can store what the code actually is. session_start(); //Now lets use md5 to generate a totally random string $md5 = md5(microtime() * mktime()); /* We dont need a 32 character long string so we trim it down to 5 */ $string = substr($md5,0,5); /* Now for the GD stuff, for ease of use lets create the image from a background image. */ $captcha = imagecreatefromjpeg("http://echoing.org/captcha.jpg"); /* Lets set the colours, the colour $line is used to generate lines. Using a blue misty colours. The colour codes are in RGB */ $black = imagecolorallocate($captcha, 0, 0, 0); $line = imagecolorallocate($captcha,233,239,239); /* Now to make it a little bit harder for any bots to break, assuming they can break it so far. Lets add some lines in (static lines) to attempt to make the bots life a little harder */ imageline($captcha,0,0,39,29,$line); imageline($captcha,40,0,64,29,$line); /* Now for the all important writing of the randomly generated string to the image. */ imagestring($captcha, 5, 20, 10, $string, $black); /* Encrypt and store the key inside of a session */ $_SESSION['key'] = md5($string); /* Output the image */ header("Content-type: image/jpeg"); imagejpeg($captcha); ?>I don’t know where it all went wrong as I’m using pretty much the same code without problems here, here and here. The form isn't being used presently (apart from the spam) but I am itching to know what the problem is. P.S. The link to the CAPTCHA image wasn’t always http://echoing.org/captcha.php in the code. On the other forms and initially with this one the code was ./captcha.php but I changed it in case that was the problem. Looks like it isn’t. Thanks in advance! Hi I'm trying to set up my first contact form, but I keep getting this error message:
Parse error: syntax error, unexpected end of file in /home/remem539/public_html/php/testform.php on line 85
here's my code, what am I doing wrong?
<?php
if ($_POST['parse_var'] == "testform"){ I have an array for recipients 'recipients' => array( 'user@example.com', ),() and I need to mail different recipients by form option, something like this switch($_POST['color']){ case 'red': $recipient = 'redperson@example.com'; break; case 'green': $recipient = 'greenperson@example.com'; break; case 'blue': $recipient = 'blueperson@example.com'; break; default: $recipient = 'user@example.com'; }() I don't know how to combine the two? How to add SMTP authentication for PHP mail form which is using POST function... |