PHP - Simple Email Form Keeps Sending Email To Spam Folder
Hi the user fill details and then the email his sent to me the only problem is that the emails keeps going to my spam, can someone help me out please I looked already php website and email format looks the same.
This is the link to my form. http://www.people.eurico.co.uk/ here my form script Code: [Select] <?php // Set email variables $email_to = 'xxxxx@xxxxxxx.co.uk'; $email_subject = 'Call back form'; // Set required fields $required_fields = array('fullname','email','telephone','comment'); // set error messages $error_messages = array( 'fullname' => 'Please enter a Name to proceed.', 'email' => 'Please enter a valid Email.', 'telephone' => 'Please telephone.', 'comment' => 'Please enter your Message to continue.' ); // Set form status $form_complete = FALSE; // configure validation array $validation = array(); // check form submittal if(!empty($_POST)) { // Sanitise POST array foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value)); // Loop into required fields and make sure they match our needs foreach($required_fields as $field) { // the field has been submitted? if(!array_key_exists($field, $_POST)) array_push($validation, $field); // check there is information in the field? if($_POST[$field] == '') array_push($validation, $field); // validate the email address supplied if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field); } // basic validation result if(count($validation) == 0) { // Prepare our content string $email_content = 'peoplesmartlearning.co.uk: ' . "\n\n"; // simple email content foreach($_POST as $key => $value) { if($key != 'submit') $email_content .= $key . ': ' . $value . "\n"; } // if validation passed ok then send the email mail($email_to, $email_subject, $email_content); // Update form switch $form_complete = TRUE; } } function validate_email_address($email = FALSE) { return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE; } function remove_email_injection($field = FALSE) { return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field)); } ?> The HTML Code: [Select] <div class="call_us_form"> <p class="title">WE'LL CALL YOU BACK</p> <?php if($form_complete === FALSE): ?> <form class="contact_form" id="fm-form" method="post" action="index.php" > <fieldset> <div class="fm-req"> <label for="fm-firstname">Name</label> <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /> <?php if(in_array('fullname', $validation)): ?><script type="text/javascript">alert("Please enter a Name"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Email</label> <input type="text" id="email" class="detail" name="email" value=" <?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /> <?php if(in_array('email', $validation)): ?><script type="text/javascript">alert("Please enter a valid Email Address"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Number</label> <input type="text" id="telephone" class="detail" name="telephone" value="<?php echo isset($_POST['telephone'])? $_POST['telephone'] : ''; ?>" /> <?php if(in_array('telephone', $validation)): ?><script type="text/javascript">alert("Please enter telephone number"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-lastname">Message</label> <textarea cols="40" rows="5" id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea> <?php if(in_array('comment', $validation)): ?><script type="text/javascript">alert("Please enter your message"); history.back();</script><?php endif; ?> </div> <input class="submit_button" type="submit" value="Call us" /> </fieldset> </form> <?php else: ?> <p>Thank you for your Message!</p> <p>We will get back to you as soon as we can</p> <script type="text/javascript"> setTimeout ('ourRedirect()', 5000) function ourRedirect () { location.href='index.php' } </script> <?php endif; ?> Similar TutorialsHello all, I used simple php email function but it send an email in junk folder or spam. Can anyone tell me why is this so? Her is the code: $host = "ssl://smtp.gmail.com"; $port = "465"; $to = " xx@gmail.com"; // note the comma $subject = " $_POST[company_website] "; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: About Wholesale Account' . "<$_POST[email]>\r\n"; $headers .= 'Cc: mail@gmail.com' . "\r\n"; $headers .= 'Bcc: cc@gmail.com' . "\r\n"; mail($to, $subject, $message, $headers); Here is one of my emails. Delivered-To: jason@gmail.com Received: by 10.204.57.134 with SMTP id c6cs22321bkh; Tue, 13 Sep 2011 07:23:32 -0700 (PDT) Received: by 10.101.168.12 with SMTP id v12mr3751263ano.48.1315923810914; Tue, 13 Sep 2011 07:23:30 -0700 (PDT) Return-Path: <contact@big.com> Received: from big.com (big.com [173.0.59.100]) by mx.google.com with ESMTP id c19si889696anj.173.2011.09.13.07.23.29; Tue, 13 Sep 2011 07:23:29 -0700 (PDT) Received-SPF: pass (google.com: domain of contact@big.com designates 173.0.59.100 as permitted sender) client-ip=173.0.59.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of contact@big.com designates 173.0.59.100 as permitted sender) smtp.mail=contact@big.com; dkim=neutral (body hash did not verify) header.i=@big.com Received: by big.com (Postfix, from userid 33) id 1BDCE2F4041A; Tue, 13 Sep 2011 10:23:20 -0400 (EDT) DKIM-Signatu v=1; a=rsa-sha256; c=simple/simple; d=big.com; s=mail; t=1315923800; bh=ysNGlrscqmqCPbqxJlWWHLaW3SU6MgDVQCze+cevPS4=; h=To:Subject:Message-ID:Date:MIME-Version:Sender:From:Reply-To: Content-Type; b=PDPCRvKGQRP3LeeDNhZQwbX6aMXOZEyqRXV1E+kuDDq05NYRIrmJCcQRhwEIaSosh yoZ0pF5wtrXjgY1KA0hgee7qzSVDhweguBfOydn1qE6nsL1pq CQgsHmtvu9dwPGw9z uUEHM9bg5DwiG0RT5KLYf4oZTJmJpc8n2oyK26/I= To: jason@gmail.com Subject: Closed Beta Invitation from Jason Gordon Message-ID: <87847890-050333@big.com> Date: Tue, 13 Sep 2011 10:38:17 -0400 MIME-Version: 1.0 X-Mailer: PHP-5.3.8 X-Sender: "big" <contact@big.com> X-Priority: 3 Organization: big Errors-To: contact@big.com Sender: contact@big.com From: "big" <contact@big.com> Reply-To: "big" <contact@big.com> Content-Type: multipart/alternative; boundary=87847890 --48673093 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit <a href="http://big.com/u/jasonGordon?utm_source=beta_invite&utm_medium=email&utm_content=referer_name&utm_campaign=join_beta" alt="Jason Gordon's profile" title="Jason Gordon's profile">Jason Gordon</a> invited you to join the newest community of entreprenuers and investors, big. Why participate in our closed beta? Here you will be able to find, research and connect with entrepreneurs or investor so much easier than ever before. You will be one of the first people to ever lay eyes on our exclusive software! Sign up by clicking <a href="http://big.com/join?9b782e=&key=7RG5poe9lgxmUSIcQTPji8EtFMnXyOYW3Cf&utm_source=beta_invite&utm_medium=email&utm_content=sign_up&utm_campaign=join_beta" title="big Beta Referral">here</a> If the link does not work, go to <a href="http://big.com" title="big">big.com</a>, click "Join big" and enter your closed beta access key. Your closed beta access key is: 7RG5poe9lgxmUSIcQTPji8EtFMnXyOYW3Cf Please leave us feedback so that we can improve our software. big Team --48673093 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit <!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>Closed Beta Invitation</title> </head> <body> <table width="500px" cellspacing="0" cellpadding="13" style="border: 1px solid #e7e7e7;"> <tr> <td> <table cellspacing="0" cellpadding="5" bgcolor="#ffffff" width="480px" style="border: 1px solid #999999;"> <tr> <td bgcolor="#489fcc" cellspacing="15" style="border-bottom: 1px solid #999999; border-top: 0; border-left: 0; border-right: 0; font-family: verdana; letter-spacing: 1px; font-weight: bold; color: white;" width="480px"> big </td> </tr> <tr> <td> <table style="line-height: 26px; font-family: arial; font-size: 13px;" width="100%" cellspacing="10" cellpadding="0"> <tr> <td width="100%"> <table style="line-height: 26px; text-align: justify;" width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="100%"> <a href="http://big.com/u/jasonGordon?utm_source=beta_invite&utm_medium=email&utm_content=referer_name&utm_campaign=join_beta" alt="Jason Gordon's profile" title="Jason Gordon's profile">Jason Gordon</a> invited you to join the newest community of entreprenuers and investors, big. Why participate in our closed beta? Here you will be able to find, research and connect with entrepreneurs or investor so much easier than ever before. You will be one of the first people to ever lay eyes on our exclusive software! </td> </tr> </table> </td> </tr> <tr> <td align="center" width="100%"> <table style="border-top: 1px solid #b8b8b8; border-bottom: 1px solid #b8b8b8;" width="100%" cellpadding="0" cellspacing="5"> <tr> <td width="100%" align="center"> Sign up by clicking <a href="http://big.com/join?9b782e=&key=7RG5poe9lgxmUSIcQTPji8EtFMnXyOYW3Cf&utm_source=beta_invite&utm_medium=email&utm_content=sign_up&utm_campaign=join_beta" title="big Beta Referral">here</a> </td> </tr> </table> </td> </tr> <tr> <td width="100%" style="text-align: justify;"> If the link does not work, go to <a href="http://big.com" title="big">big.com</a>, click "Join big" and enter your closed beta access key. Your closed beta access key is: </td> </tr> <tr> <td align="center" width="100%"> <table bgcolor="#e6e6e6" style="border: 1px solid #b8b8b8;" width="100%" cellpadding="0" cellspacing="5"> <tr> <td width="100%" align="center"> 7RG5poe9lgxmUSIcQTPji8EtFMnXyOYW3Cf </td> </tr> </table> </td> </tr> <tr> <td width="100%"> Please leave us feedback so that we can improve our software. </td> </tr><tr> <td width="100%"> big Team </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </body> </html> --48673093-- My headers function is... Code: [Select] function mail_header ($type, $random_hash) { $type = (int)$type; if ($type === 0) { $boundary = $random_hash; $x_mailer = phpversion(); $time_stamp = date("r"); $headers = 'Message-ID: <'.$boundary.'-050333@big.com>' . "\r\n"; $headers .= 'Date: ' . $time_stamp . "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'X-Mailer: PHP-' . $x_mailer . "\r\n"; $headers .= 'X-Sender: "big" <contact@big.com>' . "\r\n"; $headers .= 'X-Priority: 3' . "\r\n"; $headers .= 'Organization: big' . "\r\n"; $headers .= 'Errors-To: contact@big.com' . "\r\n"; $headers .= 'Sender: contact@big.com' . "\r\n"; $headers .= 'From: "big" <contact@big.com>' . "\r\n"; $headers .= 'Reply-To: "big" <contact@big.com>' . "\r\n"; $headers .= 'Return-Path: "big" <contact@big.com>' . "\r\n"; $headers .= 'Content-Type: multipart/alternative; boundary=' . $boundary . "\r\n"; } return $headers; } Everything about the email is sending except the message text does anyone know what the issue could be? here is the block of code that sends the email Thanks in advance Code: [Select] $image = "http://www.visualrealityink.com/dev/clients/arzan/snell_form/images/email.png"; echo "got to process form"; $target_path = "upload/"; $path = $target_path = $target_path . basename( $_FILES['file']['name']); $boundary = '-----=' . md5( uniqid ( rand() ) ); $message .= "Content-Type: application/msword; name=\"my attachment\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment; filename=\"$path\"\n\n"; echo $path; $fp = fopen($path, 'r'); do //we loop until there is no data left { $data = fread($fp, 8192); if (strlen($data) == 0) break; $content .= $data; } while (true); $content_encode = chunk_split(base64_encode($content)); $message .= $content_encode . "\n"; $message .= "--" . $boundary . "\n"; $message .= $image . "<br />" . $_POST['name'] . "submitted a resume on our website. Please review the applications and contact the candidate if their resume is a fit for any open opportunities with the company. <br><br> Thank you. <br><br> SEI Team"; $headers = "From: \"Me\"<me@example.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\""; mail('george@visualrealityink.com', 'Email with attachment from PHP', $headers, $message); Hi, I had a website running a few months ago with a working contact form I am now building a new website and have copied the files changing relevant info but it is not not working it is sending me to the thank you page but the email is not coming through. Can anybody see why? <?php $EmailTo = "MYEMAIL@gmail.com"; $Subject = "Contact from Website"; $Title = Trim(stripslashes($_POST['Title'])); $FName = Trim(stripslashes($_POST['First Name'])); $LName = Trim(stripslashes($_POST['Last Name'])); $Email = Trim(stripslashes($_POST['Email'])); // prepare email body text $Body = ""; $Body .= "Title: "; $Body .= $Title; $Body .= "\n"; $Body .= "First Name: "; $Body .= $FName; $Body .= "\n"; $Body .= "Last Name: "; $Body .= $LName; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$Email>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">"; } ?> Code: [Select] <form action="quoteform.php" method="post" enctype="multipart/form-data" name="quoteform" id="quoteform"> <label for="Title" id="Title">Title:</label><select name="Title"> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Dr">Dr</option> <option value="Other">Other</option> </select> <label for="FName" id="FName">First Name:</label><input name="First Name" type="text" size="25"> <label for="LName" id="LName">Last Name:</label><input name="Last Name" type="text" size="25"> <label for="Email" id="Email">Email:</label><input name="Email" type="text" size="50"> <input type="submit" name="submit" value="Send" class="submit-button" title="Submit" /> <input type="button" value="Clear Message" onClick="document.forms['quoteform'].Message.value=''" /> </form> Code: [Select] $sql="SELECT * FROM $tbl_name3 WHERE review_show='n'"; $result=mysql_query($sql); $num_results=mysql_num_rows($result); if($num_results > 1){ $message="You have ".$num_results." reviews unapproved."; mail('example@example.com','GHP Reviews', $message, 'From: example@example.com'); } $sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'"; $result2=mysql_query($sql2); $num_results2=mysql_num_rows($result2); if($num_results2 > 1){ $message="You have ".$num_results2." RMA Numbers Requested."; mail('example@example.com','GHP RMA Number Requests', $message, 'From: example@example.com'); } The reviews email is being sent, however, the RMA email is not. EDIT: Nevermind, $num_results and $num_results2 should have been > 0 not > 1. Okay, below is my mailer for a contact form i created. On one site it works fine. I even have it sending to several addresses from the othersite. However this site it doesnt want to work. PHP5 and mail() function is active. <?php $Name = Trim(stripslashes($_POST['fullname'])); $EmailFrom = Trim(stripslashes($_POST['email'])); $EmailTo = "james@jd-creations.co.uk"; $Subject = Trim(stripslashes($_POST['subject'])); $answer = Trim(stripslashes($_POST['answer'])); $Comments = Trim(stripslashes($_POST['message'])); $Subject = "The Reason - Contact Us"; // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($answer)!=="20") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Comments)=="") $validationOK=false; if (Trim($Subject)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=../contact/error2.php\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Email: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=../contact/sent.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=../contact/error.php\">"; } ?> now i know it is wroking because it takes me to the sent.php page. not error.php i think it worked once. now not at all. Hello Everyone, Currently our form is not sending confirmation emails. We can see the quote requests in our content management system however are sales team is not getting the email requesting the quote. There is no option in our content management system to click this on or off so I am assuming something is not right in the code. form-process.php Code: [Select] <? session_start(); include('settings.php'); include('classes/class.formdata.php'); include('classes/class.email.php'); include('classes/class.DB.php'); include('functions/functions.general.php'); if ($_POST["PreviousOrderNumber"]){$_POST["Layout*"]=$_POST["PreviousOrderNumber"];} unset($_POST["PreviousOrderNumber"]); $newformdata = new FormData($_POST); //echo "Hello"; switch ($send_form_data) { case 'email': { if (!$_SESSION['formerrors']) { $newemail = new Email($to,$from, $subject); $newemail->SendEmail(); var_dump($_SESSION["formdata"]); unset($_SESSION["formdata"]); $redirect = $newformdata->referrer; header("Location: $redirect"); } } break; case 'email/db': { if (!$_SESSION['formerrors']) { $newemail = new Email($to,$from, $subject); $newemail->SendEmail(); $dbFormData = new DB(); $dbFormData->writePostToDB($_SESSION["formdata"],"QuoteRequests"); if (count($_FILES)>1){ $dbFormData->writeFilesToDB($_FILES,"QuoteRequests"); } unset($_SESSION["formdata"]); } } break; default: { echo 'Invalid setting in variable $send_form_data'; } break ; } //echo "END"; //exit; $redirect = $newformdata->referrer; header("Location: $redirect"); exit; $newformdata = new FormData($_POST); //var_dump($_SESSION['formerrors']) . " - " .var_dump($_SESSION["formdata"]);exit; switch ($send_form_data) { case 'email': { if (!$_SESSION['formerrors']) { $newemail = new Email($to,$from, $subject); $newemail->SendEmail(); unset($_SESSION["formdata"]); } } break ; default: { echo 'Invalid setting in variable $send_form_data'; } break ; } //insert into db if (!$_SESSION['formerrors']) { $arg = ''; $FirstName= $_POST['FirstName*']; $LastName= $_POST['LastName*']; $Company= $_POST['Company']; $Phone= $_POST['Phone*']; $Fax= $_POST['Fax']; $Email= $_POST['Email*']; $PONumber= $_POST['PONumber']; $Address= $_POST['Address*']; $ApartmentOrUnitNumber= $_POST['ApartmentOrUnitNumber']; $City= $_POST['City*']; $State= $_POST['State*']; $Zip= $_POST['Zip*']; $Quantity= $_POST['Quantity*']; $Height= $_POST['Height*']; $Width= $_POST['Width*']; $Characters= $_POST['Characters*']; $AdditionalCharacters= $_POST['AdditionalCharacters']; $Metal= $_POST['Metal*']; $Border= $_POST['Border*']; $Texture= $_POST['Texture*']; $Color= $_POST['Color*']; $Finish= $_POST['Finish*']; $Mounting= $_POST['Mounting*']; $Font= $_POST['Font*']; $Capitalization= $_POST['Capitalization*']; $Proof= $_POST['Proof*']; $Layout= $_POST['Layout*']; $Logo= $_POST['Logo']; $SpecialInstructions= $_POST['SpecialInstructions']; //echo "Done"; exit; $arg = "INSERT INTO `healypla_general`.`QuoteRequests` (`Quote_Id`, `FirstName`, `LastName`, `Company`, `Phone`, `Fax`, `Email`, `PONumber`, `Address`, `ApartmentOrUnitNumber`, `City`, `State`, `Zip`, `Quantity`, `Height`, `Width`, `Characters`, `AdditionalCharacters`, `Metal`, `Border`, `Texture`, `Color`, `Finish`, `Mounting`, `Font`, `Capitalization`, `Proof`, `Layout`, `Logo`, `SpecialInstructions`, `DateSubmitted`) VALUES (NULL, '$FirstName ', '$LastName', '$Company', '$Phone', '$Fax', '$Email', '$PONumber', '$Address', '$ApartmentOrUnitNumber', '$City', '$State', '$Zip', '$Quantity', '$Height', '$Width', '$Characters', '$AdditionalCharacters', '$Metal', '$Border', '$Texture', '$Color', '$Finish', '$Mounting', '$Font', '$Capitalization', '$Proof', '$Layout', '$Logo', '$SpecialInstructions', CURRENT_TIMESTAMP);"; $newdb = new DB($dbhost, $dbuser, $dbpass, $dbname); $arg = $arg; $result1 = $newdb->insert_db($arg); } $redirect = $newformdata->referrer; if ($_SESSION['formerrors']) { header("Location: $redirect"); } else { echo "Done";} exit; ?> $FirstName= $_POST['FirstName*']; $LastName= $_POST['LastName*']; $Company= $_POST['Company']; $Phone= $_POST['Phone*']; $Fax= $_POST['Fax']; $Email= $_POST['Email*']; $PONumber= $_POST['PONumber']; $Address= $_POST['Address*']; $City= $_POST['City*']; $State= $_POST['State*']; $Zip= $_POST['Zip*']; $Quantity= $_POST['Quantity*']; $Height= $_POST['Height*']; $Width= $_POST['Width*']; $Characters= $_POST['Characters*']; $AdditionalCharacters= $_POST['AdditionalCharacters']; $Metal= $_POST['Metal*']; $Border= $_POST['Border*']; $Texture= $_POST['Texture*']; $Color= $_POST['Color*']; $Finish= $_POST['Finish*']; $Mounting= $_POST['Mounting*']; $Font= $_POST['Font*']; $Capitalization= $_POST['Capitalization*']; $Proof= $_POST['Proof*']; $Layout= $_POST['Layout*']; $Logo= $_POST['Logo']; $SpecialInstructions= $_POST['SpecialInstructions']; then settings.php Code: [Select] <? //Global settings //Handles what to do with form data after it has been validated //email or database $send_form_data = 'email/db'; //Email settings //Where to send email $to = 'sales@healyplaques.com'; //Where it came from $from = 'quote'; //Subject of email $subject = 'Custom Plaque Quote - '; //Database settings ?> Any help would be extremely appreciated! Thanks, Amanda Smith Hello, I'm new to PHP but i am quite good with javascript programming etc so i'm just getting to terms with using PHP. I've made a contact form with an IF statement that will display confirmation within my page upon post. (I'm not even sure if this logic is right however). The form seems to submit but doesn't show the confirmation message and doesn't send an email to my webserver. Code: [Select] <body> <div id="outer"> <div id="topbar"> </div> <div id="topback"> <img src="images/logo.png" class="logo" /> <a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('hemcurrent','','images/homecurrent.png',1)"><img src="images/home.png" class="logo hem" name="hemcurrent" /></a> <a href="Tjanster.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('tjanstercurrent','','images/tjanstercurrent.png',1)"><img src="images/tjanster.png" class="logo links" name="tjanstercurrent" /></a> <a href="OmOss.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('omosscurrent','','images/omosscurrent.png',1)"><img src="images/omoss.png" class="logo links" name="omosscurrent" /></a> <a href="Referenser.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('referensercurrent','','images/referensercurrent.png',1)"><img src="images/referenser.png" class="logo links" name="referensercurrent" /></a> <a href="KontaktaOss.html"><img src="images/kontaktaosscurrent.png" class="logo links" /></a> </div> <div id="maincontent"> <h1>Nordströms HRK AB - </h1> <h2 class="kontaktaoss"> KONTAKTA OSS</h2> <?php if ($_POST["email"]<>'') { $ToEmail = 'michel@hissorulltrappskonsulter.se'; $EmailSubject = 'Webform Hissorulltrapp'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"].""; $MESSAGE_BODY .= "Email: ".$_POST["email"].""; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> Your message has been sent <?php } else { ?> <form name="form" id="form" action="KontaktaOss.php" method="post"> <select name="sDepartment" onchange="MM_jumpMenu('parent',this,0)" class="selectDepartment"> <option>Hiss och rulltrappstjänster</option> <option>Teknisk support</option> </select> <input type="text" name="subject" id="name" class="txtDepartment" /> <textarea name="tComments" id="comment" class="txtComments"></textarea> <input type="text" name="tEmail" id="email" class="txtEmail" /> <input type="image" src="images/submit.png" class="bSubmit" value="send" /> <input type="image" src="images/reset.png" class="bReset" /> </form> <?php }; ?> <p class="kontaktaossdetails"><b>Information:</b><br /> Stationsvägen 4C<br /> Täby 187 30 <br /> Telefon: 0702698981<br /> bjorn@hissotrulltrappskonsulter.se<br /> michel@hissorulltrappskonsulter.se<br /> <b>Teknisk Support:</b><br /> joel@hissorulltrappskonsulter.se</p> </div> <div id="tagline"><img class="quote1" src="images/quote1.png" /> <div id="elem0" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem1" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem2" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem3" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem4" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem5" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem6" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem7" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem8" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem9" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem10" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem11" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <img class="quote2" src="images/rightquote.png" /> <img src="images/btnLogin.png" class="btnlogin" /> </div> <div id="copyright"> <ul id="nav"> <li>LANGUAGES: </li> <li><a href="#">ENGLISH</a></li> <li><a href="#">SWEDISH</a></li> <li><a href="#">HELP</a></li> <li>COPYRIGHT BY NORDSTRÖMS HRK AB</li> </ul> </div> <div id="mac"> <div id="macscreen"> <iframe width="336" height="216" src="http://www.youtube.com/embed/AhfK9_ZlRXQ?hl=en&fs=1&rel=0&autoplay=1&autohide=1&showinfo=0&controls=0&loop=1" frameborder="0"></iframe> </div> </div> </div> </body> Just looking for some advice really, i'm sure it's something very simple! Thank you. Hi, am having abit of a problem.Can anyone help me in programming my form to send it's details to an email address.The form should be able to detect unfilled fields,unselected items all in all the form should work as a effectively according to how i designed it The email sending processing should be handled by a separate file known as process.php below is the HTML coding... <form name="myform" action="process.php" method="POST"> Name: <input type="text" name="Name" /><br /> Email: <input type="text" name="Email" /><br /> Select something from the list: <select name="Seasons"> <option value="Spring" selected="selected">Spring</option> <option value="Summer">Summer</option> <option value="Autumn">Autumn</option> <option value="Winter">Winter</option> </select><br /><br /> Choose one: <input type="radio" name="Country" value="USA" /> USA <input type="radio" name="Country" value="Canada" /> Canada <input type="radio" name="Country" value="Other" /> Other <br /> Choose the colors: <input type="checkbox" name="Colors[]" value="green" checked="checked" /> Green <input type="checkbox" name="Colors[]" value="yellow" /> Yellow <input type="checkbox" name="Colors[]" value="red" /> Red <input type="checkbox" name="Colors[]" value="gray" /> Gray <br /><br /> Comments:<br /> <textarea name="Comments" rows="10" cols="60">Enter your comments here</textarea><br /> <input type="submit" /> </form> EDIT, CORRECTION- IT WENT TO MY JUNKMAIL. HOW DO I PREVENT THAT? ALSO, IT DID NOT PUT THE USER'S IP IN THE 'POSTER' FIELD IN DB SO I CAN PREVENT MULTIPLE POSTS PER PERSON. Hi, I went over the code and looks good to me, I put the "poster" field in my Members table. Everything looks good, my page loads with no errors, but the email never gets sent upon submitting the form "user poll" here is the relevant code, please any help greatly appreciated! thank you. Code: [Select] <?php if($_POST['submit']) { $currentPoster = $_SERVER['REMOTE_ADDR']; // get ip of visitor $query = mysql_query("SELECT * FROM members WHERE poster = '$currentPoster'"); //check DB for user ip if (mysql_num_rows($query) > 0) //if ip exists, user already posted { $error=1; //this is t o set if error message echoes or not. $errorMessage=" You already posted to this poll"; // echo error to the multiple post prick//echoed out below } else { $query2 = mysql_query("INSERT INTO members(poster) VALUES ('$currentPoster')");// insert new ip into DB $email_from = '.info POLL'; // email information $email_subject = " POLL RESPONDER"; $email_body = "You have received a new poll message from the user ip address of $currentPoster.\n". "Here is the message:\n $userfeedback"; //////////////////////////////////////////////////////////////////////// //SEND THE EMAIL $to = "xxxx@hotmail.com"; //email headers $headers = "From: $email_from \r\n"; $headers .= "Reply-To: no one \r\n"; mail($to,$email_subject,$email_body,$headers);// sends off the final email. $error=0; $goodmessage="Thank you for your feedback!"; } } ?> <form id="userfeedback" method="post" action="index.php"> <p> <textarea name="userfeedback" id="userfeedback" cols="45" rows="5"></textarea> <input type="submit" id="submit" name="submit"/> <input type="reset" id="reset" name="reset"/> </p> </form> <br/> <?php if($error=1) { echo $errorMessage; }else { echo $goodmessage; } ?> Hello, I am very very new to PHP and have created a form that changes depending on a selection option. The website is here http://www.rmdesignstudio.com.au/wraptinprint/quotes.php and the PHP is all on the quotes.php page. The form sends to the email but when you fill in one form (example: Business Cards) the form sends, but along with all the entered fields the email also includes all the fields in all the hidden forms that werent filled in. I believe it is because they are drop down boxes and it is sending the first option in the list which happens to be "-----Please Select-----" Is there something I should be doing to my selection input field for this not to show up? Otherwise is there something I need to add to my PHP so it checks for the fields being filled in? I dont know how to add my code to this post, so if you could either show me or view my code via view source that would be awesome. Hi guys, i was wondering how can i make php to generate custom image with required fields (contact form). For example, i have a page with first name, last name, full address, email. And it's like this: First name: <input field here> Last name: <input field here> Full Address: <input field here> Email: <input field here> I would like to know how can i (once they fill all the info) generate an image with custom background (prepared full image previously) with all the filled info and have it emailed back to him. That email should be something like: Dear, FirstName, Here's your full info displayed on image below <img src="/path/to/thatImage.png"></img> Is this even possible? If so, please let me know how, i used to google a lot, but i can't find a solution, and i'm beginner in coding. Hope you guys will help me out, thanks a lot in advance! I really need some help. I am very new to PHP and I've been stuck for a couple of days. I created a contact form and everything seems to be working correctly, except the mail is showing it's sent, but I never receive an email in my Inbox or Spam folder. Can someone please review my code? Here is the PHP: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varpositionErr = ""; $varfname = $varlname = $varemail = $varphone = $varposition = $success = ""; //FORM SUBMITTED WITH POST METHOD if ($_SERVER["REQUEST_METHOD"] == "POST") { //VALIDATE FIRST NAME if (empty($_POST["varfname"])) { $varfnameErr = "First Name is required"; } else { $varfname = test_input($_POST["varfname"]); // MAKE SURE FIRST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varfname)) { $varfnameErr = "Only letters and white space are allowed"; } } //VALIDATE LAST NAME if (empty($_POST["varlname"])) { $varlnameErr = "Last Name is required"; } else { $varlname = test_input($_POST["varlname"]); // MAKE SURE LAST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varlname)) { $varlnameErr = "Only letters and white space are allowed"; } } //VALIDATE EMAIL ADDRESS if (empty($_POST["varemail"])) { $varemailErr = "Email Address is required"; } else { $varemail = test_input($_POST["varemail"]); // MAKE SURE EMAIL ADDRESS IS FORMATTED CORRECTLY if (!filter_var($varemail, FILTER_VALIDATE_EMAIL)) { $varemailErr = "Invalid email address format"; } } //VALIDATE PHONE NUMBER if (empty($_POST["varphone"])) { $varphoneErr = "Phone number is required"; } else { $varphone = test_input($_POST["varphone"]); // MAKE SURE PHONE NUMBER IS IN CORRECT FORMAT if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$varphone)) { $varphoneErr = "Invalid telephone format"; } } //VALIDATE POSITION if (empty($_POST["varposition"])) { $varpositionErr = "Position is required"; } else { $varposition = test_input($_POST["varposition"]); } //IF ALL DATA IS CORRECT if ($varfnameErr == '' and $varlnameErr == '' and $varemailErr == '' and $varphoneErr == '' and $varpositionErr == '') { $message_body = ''; unset($_POST['submit']); //THIS IS JUST FOR TESTING PURPOSES $message_body = $varfname; //foreach ($_POST as $key => $value) { // $message_body .= "$key: $value\n"; //} $to = 'mygmail@gmail.com'; $subject = 'Volunteer Form Submission'; $message = wordwrap($message_body, 70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: " . $varemail . "\r\n"; $subject = 'Volunteer Form Submission'; $to = 'mygmail@gmail.com'; $result = mail($to, $subject, $message, $headers); //THIS RETURNS "1" print $result; //IF ALL DATA IS CORRECT MAKE SURE EMAIL WAS SENT if (mail($to, $subject, $message, $headers)) { $success = "Message sent. Thank you contacting us! We will reply as soon as possible."; $varfname = $varlname = $varemail = $varphone = $varposition = ""; } else { $success = "Something went wrong!"; } } } //STRIP UNWANTED CHARACTERS FROM VARIABLES function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
Here is the HTML: <div class="row regformrow"> <div class="coffee-span-12 regformcolumn"> <div class="subgrid regformsubgrid"> <div class="row regformsubgridheaderrow"> <div class="coffee-span-12 regformsubgridheadercolumn"> <h4 class="regformsubgridheadertitle">Volunteer Form</h4> </div> </div> <div class="row regformsubgridrow"> <form class="form-container regformsubgridformcontainer" action=<?= $_SERVER['PHP_SELF']; ?> method="post"> <div class="coffee-span-4 coffee-972-span-6 coffee-458-span-12 regformsubgridcolumn1"> <div class="container regformsubgridcontainer1"> <label class="label form-label-all"><span style="font-style:italic;color:#FF5454;">* Required Fields</span></label></br> <div class="formfieldgroup"> <input class="fname" name="varfname" type="text" tabindex="1" placeholder="First Name" value="<?= $varfname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varfnameErr ?></span> </div> <div class="formfieldgroup"> <input class="lname" name="varlname" type="text" tabindex="2" placeholder="Last Name" value="<?= $varlname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varlnameErr ?></span> </div> <div class="formfieldgroup"> <input class="email" name="varemail" type="text" tabindex="2" placeholder="Email Address" value="<?= $varemail; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varemailErr ?></span> </div> <div class="formfieldgroup"> <input class="phone" name="varphone" type="text" tabindex="2" placeholder="Telephone Number" value="<?= $varphone; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varphoneErr ?></span> </div> <div class="formfieldgroup"> <select class="select selectbox" name="varposition" id="varposition" tabindex="5"><option value="">Select one...</option><option value="Chaperone">Chaperone</option><option value="Class Monitor">Class Monitor</option><option value="Parking Attendant">Parking Attendant</option><option value="Party Coordinator">Party Coordinator</option><option value="Teacher Aid">Teacher Aid</option></select><span class="requiredfield"> *</span> <span class="form-error"><?= $varpositionErr ?></span> </div> <div class="formfieldgroup"> <input class="test" name="test" type="text" tabindex="6" placeholder="If you are human, leave this field blank" value=""> </div> <div class="formfieldgroup"> <button type="submit" class="button-submit-1" name="submit" tabindex="7" data-submit="...Sendng">Submit</button> </div> <div class="formfieldgroup"> <div class="success"><?= $success; ?></div> </div> </div> </div> </form> </div> </div> </div> </div> Edited February 20, 2020 by mike3075 Hi I am very new to PHP. I'm wanting a feedback form on my website where the form is sent via SMTP rather than sendmail. I have checked that php is working by doing this code: Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', True); $path = '/home/****/php'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); echo("<p>Sending PEAR Mail.php...</p>"); require('Mail.php'); $from = "Info <info@***.co.uk>"; $to = "Info <info@***.co.uk>"; $subject = "Hi - Test message!"; $body = "Hi,\n\nHow are you?"; $host = "mail.***.co.uk"; $username = "info@***.co.uk"; $password = "***"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> This works fine. I then created a form in my contact page: Code: [Select] <form name="feedbackform" action="form-mailer2.php" method="post"> <input type="hidden" name="Required" value="Name,Comments"> <p>Name: <input name="Name" size="30"> <span class="formsmall">required</span></p> <p>E-mail: <input name="Email" size="30"> <span class="formsmall">optional</span></p> <p>Feedback/Comments:</p> <p><textarea name="Comments" rows="5" cols="40"></textarea></p> <p><input type="submit" value="Submit" name="submitform"><input type="reset" value="Reset" name="reset"></p> </form> I then used the code based on the php initial example and the code file that would get the form details from the contact page and send to the email address via smtp. I have left the validations in - although if these are no good please feel free to tell me! I will want to put a captcha in but need to look into that yet. Anyway, the code I have created is now this (which is saved in the file form-mailer2.php): Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', True); $path = '/home/****/php'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); echo("<p>Sending PEAR Mail.php...</p>"); require('Mail.php'); $mailfrom = "info@***.co.uk"; $mailTo = "info@***.co.uk"; $mailSubject = "Web Feedback"; $mailHost = "mail.***.co.uk"; $mailPort = "25"; $mailAuth = "true"; $mailPassword = "****"; // Get the form fields. $name = $_POST['Name']; $email = $_POST['Email']; $comments = $_POST['Comments']; $reqFields = $_POST['Required']; // I find including the time/date useful for record-keeping. // Note that it is the web server's time/date, not yours // or the sender's. $date = date("l jS F Y, g:i A"); // A simple yet reasonably effective email address validator. if ((!ereg(".+\@.+\..+", $email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $email))) { $errorMessages .= "<li>Invalid email address: $email</li>"; } // Make sure required fields are filled in. $checkFields = explode(",",$reqFields); while(list($theField) = each($checkFields)) { if(!$$checkFields[$theField]) { $errorMessages .= "<li>Missing $checkFields[$theField]</li>"; } } // If there are errors, display them and a back button. if($errorMessages) { ?> <p>Errors were found on the form.</p> <ul> <?php echo $errorMessages; ?> </ul> <p><input type="button" value="Back" onClick="history.back()"></p> <?php } // No errors, send the message and print out success message. else { // Build the email. $body = " Name: $Name Email: $Email Phone: $Phone ----- Comments ----- $Comments -------------------- $headers["From"] = $mailTo; $headers["To"] = $mailTo; $headers["Subject"] = $mailSubject; $params["host"] = $mailHost; $params["port"] = $mailPort; $params["auth"] = $mailAuth; $params["username"] = $mailTo; $params["password"] = $mailPassword; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($mailTo, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } // I would rather redirect to a different thank you page but both of next options don't work when taking out: echo("<p>Message successfully sent!</p>"); //RedirectToURL("thank-you.php"); or header(Location: "thank-you.php" ); ?> Depending on what I change about I either get: The website cannot display the page or a list of undefinable variables. If anyone is able to understand the php and notice where the problem lies I would be so grateful. Thank you. I have an HTML form that I have a "select" drop-down menu that is selecting the name of the person you should send to. The names are being pulled from the Database, and here is what that code for the drop-down in the form looks like: <?php echo '<select name= "First_Name" , "Last_Name">'; while( $array = mysql_fetch_assoc($result) ) { $text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"]; $value_for_select = $array["First_Name"] . " " . $array["Last_Name"] . "_" . $array["id"]; echo "<option></option>\n"; echo "<option value=\"$value_for_select\">$text_for_select</option>\n"; } echo '</select>';?> This works perfectly. However, what I want it to do is send the form to the email address of the person that is selected in the drop-down. The email address' are already entered in each record of the database in a field called "Email". I am using the $value_for_select variable to pull the id of the record, but I am unsure how to then tell the form to send to the email address of that record? Anybody know a way that this can be done? Here is the code of the for that should be sent: <?php if($_POST){ $to = $email; $subject = "WHAT SHOULD THIS BE"; $message = "Date: $date\n\r". "Dear $First_Name, $Last_Name,\n\r". "Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah..\n\r". "Sincerely,\n". "$name \n". "$street \n". "$city, $zip \n". "$email \\n". $headers = "From: $email"; mail($to, $subject, $message, $headers); // SUCCESS! echo '<p class="notice">'. 'Thank you for your submission. '. '</p>'; // clear out the variables for good-housekeeping unset($date,$legislator,$bill,$name,$street,$city,$zip,$email); $_POST = array(); } ?> Please help! i am using mail functions in php and i am sending mails but the mails are going to spam in gmail and for yahoo its going to inbox. my problem is i want to send the email to inbox only as most of them use gmail ....should i use any smtp or any other mail library functions? can anyone guide me? Hey everyone. I hope you can help me getting through this problem, because I have no idea of what else to try. I'm a web designer and sometimes modify Javascript, but my main focus is HTML and CSS, meaning I have no idea how to code in Javascript, but most importantly, how to write something from scratch in PHP. So I designed a form that works pretty well, and integrated a PHP and Javascript script to make it work. This is the form: Code: [Select] <form name="form" id="form" method="post" action="contact.php"> <p>Hello,</p> <p>My name is <input type="text" name="name">, from <input type="text" name="location">, and I'd like to get in touch with you for the following purpose:</p> <p><textarea name="message" rows="10" ></textarea></p> <p>By the way, my email address is <input type="text" name="email" id="email" placeholder="john@doe.com">, and I can prove I'm not a robot because I know the sky is <input type="text" name="code" placeholder="Red, green or blue?">.</p> <p title="Send this message."><input type="submit" id="submit" value="Take care."></p> </form> And this is the script, in an external file called contact.php: Code: [Select] <?php $name = check_input($_REQUEST['name'], "Please enter your name.") ; $location = check_input($_REQUEST['location']) ; $message = check_input($_REQUEST['message'], "Please write a message.") ; $email = check_input($_REQUEST['email'], "Please enter a valid email address.") ; if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {die("E-mail address not valid");} if (strtolower($_POST['code']) != 'blue') {die('You are definitely a robot.');} $mail_status = mail( "my@email.com", "Hey!", "Hello,\n\n$message\n\nRegards,\n\n$name\n$location", "From: $email $name" ); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for the message. I will try to respond as soon as I can.'); window.location = '/about'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('There was an error. Please try again in a few minutes, or send the message directly to aalejandro@bitsland.com.'); window.location = '/about'; </script> <?php } ?> So what it does is this: if everything's OK, it sends an email with "Hey!" as the subject, "[name]" as the sender, "Hello, [message]. Regards, [name], [location]" as the body, and a popup saying the message was delivered appears. If something fails, it outputs the error in a new address, so the user will have to go back to the form and correct the error. What I actually want to happen is this: if everything's OK, a <p> which was hidden beneath the form appears saying the message was delivered, or, alternatively, make the submit button gray out and confirm the message was delivered. I found a script to make this happen, but with "Please wait...", so the user can't resubmit the form. If there's an error, I'd like another <p> which was hidden to appear with the specific error, so there'd be many <p>'s hidden with different IDs. If possible, I'd also like to change the CSS style of the input field, specifically changing the border color to red, so it'd be a change in class for the particular field. -- So in essence, I want the errors and the success messages to output in the same page as the form (without refresh), and a change of class in the input fields that have an error. Thanks in advance, and please let me know if it'll be possible. HI, i have a problem, a big one. I used a php script to send some info from my html forms to my gmail. So it functions easy, somebody fills out the form and he click send, after that, his information is sent to me on my gmail, and i can work with it later. Now stupid google have some new filters (from year 2014 ) and it treats some of those mails as spam. Code is written in the way that allows me to get those mails as it is sent from the user himself, from his email. Can anybody correct my script so it won't be treated as a spam, because i know it is possible but don't know how... here is the code - https://gist.github....67145d500c5cf47 // Receiving variables From our website we are connecting to GMAIL to send our emails through SMTP. For some reason it is not sending the emails to the CC or BCC email address event though GMAIL shows it was included in the email. Am I missing something in the below code? Code: [Select] $currentTime = time(); $emailTo = "redbrad0@domain.com"; $emailCC = "brad@domain.com"; $emailBCC = "events@domain.com"; $emailSubject = "TEST Email at (" . $currentTime . ")"; $emailBody = "This is the body of the email"; $headers = array(); if (!empty($emailTo)) $headers['TO'] = $emailTo; if (!empty($emailCC)) $headers['CC'] = $emailCC; if (!empty($emailBCC)) $headers['BCC'] = $emailBCC; if (!empty($emailSubject)) $headers['Subject'] = $emailSubject; $headers['From'] = "events@domain.com"; $mime = new Mail_mime("\n"); $mime->setTXTBody($emailBody); $body = $mime->get(); $headers = $mime->headers($headers); $mail = Mail::factory('smtp', array ('host' => 'ssl://smtp.gmail.com', 'auth' => true, 'port' => 465, 'username' => 'events@domain.com', 'password' => 'thepasswordhere')); try { $result = $mail->send($emailTo, $headers, $emailBody); } catch (TixException $ex) { echo "<font color=red>Error:" . $ex->getCode() . "</font><br>"; } echo "Emailed at (" . $currentTime . ")<br>"; die; Hello, I am working with a SMTP class to send an email. It's all working perfectly fine, but when the email is received (sent from the online form), and I open my email and click reply, there are two email addresses. The correct one (which I entered when I sent the email), and my ftp username for the site?? I've got three files that could effect this, but I was unable to locate any problems: mailer.php ( smtp send mail class) mail.php ( submission data: title, subject, etc. ) contact_form.php ( form for submission ) I am only including the file which I think is applicable (mail.php), but let me know if you would also like to see the mailer.php class. Current output: reply-to ftpusername@domainname.com, correct_from_email@fromemail.com mail.php: <?php set_time_limit(120); function sendHTMLmail($from, $to, $subject, $message) { $message = wordwrap($message, 70); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= "From: $from\r\n"; // Mail it mail($to, $subject, $message, $headers); } function sendHTMLmail2($fromid, $to, $subject, $message) { echo $fromid; echo $to; echo $subject; echo $message; include_once("mailer.php"); $mail = new PHPMailer(); $mail->IsMail(); // SMTP servers $mail->Host = "localhost"; $mail->From = $fromid; $mail->FromName = $fromid; $mail->IsHTML(true); $mail->AddAddress($to, $to); $mail->Subject = $subject; $mail->Body = $message; $mail->AltBody = "Please enable HTML to read this"; $mail->Send(); exit; } function isValidEmail($email) { return eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $email); } class smtp_mail { var $host; var $port = 25; var $user; var $pass; var $debug = false; var $conn; var $result_str; var $charset = "utf-8"; var $in; var $from_r; //mail format 0=normal 1=html var $mailformat = 0; function smtp_mail($host, $port, $user, $pass, $debug = false) { $this->host = $host; $this->port = $port; $this->user = base64_encode($user); $this->pass = base64_encode($pass); $this->debug = $debug; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($this->socket) { $this->result_str = "Create socket:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->conn = socket_connect($this->socket, $this->host, $this->port); if ($this->conn) { $this->result_str = "Create SOCKET Connect:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->result_str = "Server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } function debug_show($str) { if ($this->debug) { echo $str . "<p>\r\n"; } } function send($from, $to, $subject, $body) { if ($from == "" || $to == "") { exit("type mail address please"); } if ($subject == "") $sebject = "none title"; if ($body == "") $body = "none content"; $All = "From:$from;\r\n"; $All .= "To:$to;\r\n"; $All .= "Subject:$subject;\r\n"; if ($this->mailformat == 1) { $All .= "Content-Type:text/html;\r\n"; } else { $All .= "Content-Type:text/plain;\r\n"; } $All .= "Charset:" . $this->charset . ";\r\n\r\n"; $All .= " " . $body; $this->in = "EHLO HELO\r\n"; $this->docommand(); $this->in = "AUTH LOGIN\r\n"; $this->docommand(); $this->in = $this->user . "\r\n"; $this->docommand(); $this->in = $this->pass . "\r\n"; $this->docommand(); if (!eregi("235", $this->result_str)) { $this->result_str = "smtp auth faild"; $this->debug_show($this->result_str); return 0; } $this->in = "MAIL FROM: $from\r\n"; $this->docommand(); $this->in = "RCPT TO: $to\r\n"; $this->docommand(); $this->in = "DATA\r\n"; $this->docommand(); $this->in = $All . "\r\n.\r\n"; $this->docommand(); if (!eregi("250", $this->result_str)) { $this->result_str = "Send mail faild!"; $this->debug_show($this->result_str); return 0; } $this->in = "QUIT\r\n"; $this->docommand(); socket_close($this->socket); return 1; } function docommand() { socket_write($this->socket, $this->in, strlen($this->in)); $this->debug_show("Client command:" . $this->in); $this->result_str = "server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } } ?> |