Joe Cool Posted December 2, 2009 Share Posted December 2, 2009 I started a thread a couple of months ago about the contact forms on my client's website. Basically he wants me to overhaul the SEO on his site. However, there were problems with the PHP contact forms and I had to try to rectify them. I have no experience in PHP coding so I turned to this forum for advice on fixing the problem. A few of the members kindly helped me out and I managed to fix the problem and get the contact forms to work. Here is the thread if anyone is interested: http://www.phpfreaks.com/forums/index.php/topic,271795.msg1283238.html#msg1283238 Since then the hosting company has made changes to their system "to prevent spammer mass mailing." These changes mean that enquiries are being blocked if the user has a certain email address. Namely Yahoo, Hotmail, Google, AOL or FSnet. There may be more but those are the five I'm aware of. The hosting company say an extra variable has to be added in the code to rectify this. They provided the following example on their website: PHP send mail scripts - Update. Possibly one of the most popular ways to send a form submission is the use of the PHP mail function. Due to a recent server update customers who choose to use this method will need to include an extra variable in their code. What needs to be included is; 1. A variable that tells the script where the email is being sent from; For example; $SendEmail ="enquire@domainname.com"; 2. Adding this variable onto the end of the mail() function. Below is a very basic php script, I have included the extra entries in italic. $nameField = $_POST['name']; $emailField = $_POST['email']; $SendEmail ="enquiry@domainname.com"; $body = <<< EOD Name: $nameField Email: $emailField EOD; $headers = "From: $emailField\r\n"; $headers .= "Content-type: text/html\r\n"; $sucess = mail($webMaster, $emailSubject, $headers, $body, '-f'.$SendEmail); The important part here is the '-f'.$SendEmail at the end of the mail() function. The '-f' although not a php command is a sendmail parameter that is telling our mailserver the mail is being sent from the $SendEmail address and nowhere else. This is the relevant code from one of the contact forms on my client's site: <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $mobphone = $_POST['mobphone']; $town = $_POST['town']; $county = $_POST['county']; $voucher = $_POST['voucher']; $propertyvalue = $_POST['propertyvalue']; $mortgagetype = $_POST['mortgagetype']; $hours1 = $_POST['hours1']; $minutes1 = $_POST['minutes1']; $date1 = $_POST['date1']; $hours2 = $_POST['hours2']; $minutes2 = $_POST['minutes2']; $date2 = $_POST['date2']; $info = $_POST['info']; $sendemail = "Name: $name Email address: $email Phone number: $phone Mobile number: $mobphone Town: $town County: $county Voucher: $voucher Purchase price / Property value: £$propertyvalue Mortgage type: $mortgagetype Callback 1: $hours1:$minutes1 - $date1 Callback 2: $hours2:$minutes2 - $date2 Extra info: $info"; $subject = "Mortgage call back request from company x"; $mailheaders = "From:$email\n"; $mailheaders .= "Reply-To:$email\n"; $message="".stripslashes($message); $subject=stripslashes($subject); mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders); $status = "<span style=\"color:red;\"><strong>Your call back request has been sent successfully.</strong><br />Thank you for contacting us. We aim to get back to you as you have specified.</span>"; } ?> <h1>Company X Mortgages</h1> <div class="maincont"> <? if ($status) { print "$status<br /><br /><br />\n"; } ?> <h2><strong>Local advice - It's never been so important.</strong></h2> <br> Speak to a qualified financial adviser in North Norfolk, South Norfolk, West Norfolk or North Suffolk. <br><br> Save money - Find the mortgage deal that's best for you. <br> <br> Free Advice - Leaving you to choose your mortgage lender.<br> <br> <h2>Request a Call Back</h2> <br> Please request a time you would like an adviser to call. We aim to return calls within one hour. <br> <br> <script language="javascript" type="text/javascript"> function checkform() { if (document.callback.hours1.value == '') { alert('Please enter a call back time'); return false; } else if (document.callback.minutes1.value == '') { alert('Please enter a call back time'); return false; } else if (document.callback.date1.value == '') { alert('Please enter a call back date'); return false; } else if (document.callback.email.value == '') { alert('Please enter your email address'); return false; } else if (document.callback.phone.value == '') { alert('Please enter your phone number'); return false; } return true; } </script> <form id="callback" name="callback" method="post" action="mortgages.php" style="display:inline;" onSubmit="return checkform()"> Your first choice:<br> <script language="javascript" type="text/javascript" src="datetimepicker.js"></script> <select name="hours1" id="hours1"> <option value="" selected>--</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> </select>:<select name="minutes1" id="minutes1"> <option value="" selected>--</option> <option value="00">00</option> <option value="05">05</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option> <option value="35">35</option> <option value="40">40</option> <option value="45">45</option> <option value="50">50</option> <option value="55">55</option> </select> <input name="date1" type="text" id="date1" size="10" /> <a href="javascript:NewCal('date1','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> * <br><br> Your second choice:<br /> <select name="hours2" id="hours2"> <option value="--" selected>--</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> </select>:<select name="minutes2" id="minutes2"> <option value="--" selected>--</option> <option value="00">00</option> <option value="05">05</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option> <option value="35">35</option> <option value="40">40</option> <option value="45">45</option> <option value="50">50</option> <option value="55">55</option> </select> <input name="date2" type="text" id="date2" size="10" /> <a href="javascript:NewCal('date2','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> <br><br> Your name:<br> <input name="name" type="text" id="name" size="30" /> <br><br> Your email address:<br> <input name="email" type="text" id="email" size="30" /> * <br><br> Your home phone number:<br> <input name="phone" type="text" id="phone" size="30" /> * <br><br> Your mobile phone number:<br> <input name="mobphone" type="text" id="mobphone" size="30" /> <br><br> Your town:<br> <input name="town" type="text" id="town" size="30" /> <br><br> Your county:<br> <input name="county" type="text" id="county" size="30" /> <br><br> Voucher Code:<br> <input name="voucher" type="text" id="voucher" size="30" /> <br><br> Mortgage amount:<br> £ <input name="propertyvalue" type="text" id="propertyvalue" size="25" /> <br><br> Type of mortgage required:<br> <select name="mortgagetype" id="mortgagetype"> <option selected>Select One</option> <option>-------------</option> <option value="Remortgage">Remortgage</option> <option value="Repayment">Repayment</option> <option value="First time buyer">First time buyer</option> <option value="Sert cert">Self cert</option> <option value="Buy to Let">Buy to Let</option> <option value="Interest Only">Interest Only</option> <option value="Commercial">Commercial</option> <option value="Let to Buy">Let to Buy</option> <option value="Fast Track">Fast Track</option> <option value="Holiday Let">Holiday Let</option> <option value="Self Build">Self Build</option> <option value="Renovation">Renovation</option> <option value="Property Conversion">Property Conversion</option> </select> <br><br> Different requirements:<br> <span style="font-size:12px;">If the service your require is not on the drop down list above, please describe it in the box below:</span><br> <textarea name="info" cols="50" rows="5" id="info"></textarea> <br><br> <input type="submit" name="button" id="button" value="Confirm Call Back" /> </form> <br><br> Required fields are marked with a *</div> Is there any way this code can be slightly tweaked to include the extra variable mentioned by the hosting company? As I mentioned, I don't have any PHP experience so I don't want to try and create contact forms from scratch or significantly alter the existing forms. Any help would be greatly appreciated. Regards, Joe. Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders, '-fenquiry@companyx.co.uk'); Assuming companyx.co.uk is your domain. Quote Link to comment Share on other sites More sharing options...
Joe Cool Posted December 2, 2009 Author Share Posted December 2, 2009 Thanks for your reply. I replaced the line: mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders); I replaced it with the following: (Obviously adding the correct email address and domain name) mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders, '-fenquiry@companyx.co.uk'); Unfortunately, it didn't make any difference. The same email addresses are still being blocked. Adding something to the 'From' header may work. If 'From' is associated with the domain name the email should go through. What do you think? Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 Sorry I had that wrong the "-f enquiry@domain" needs to be your domain. Quote Link to comment Share on other sites More sharing options...
Joe Cool Posted December 2, 2009 Author Share Posted December 2, 2009 Let's say for talking sake the domain name is www.companyx.co.uk and the contact email address is info@companyx.co.uk Are you saying the altered line of code should be? mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders, '-f info@companyx.co.uk'); Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 Yes after the -f needs to be the email address of your domain. Currently your "From" value is the email of the person submitting this form which is what causes this to be flagged as spam sich it doesnt match your domain. Make sense? Quote Link to comment Share on other sites More sharing options...
Joe Cool Posted December 2, 2009 Author Share Posted December 2, 2009 Yes it makes sense mate. The problem is it's not working. It's not changing the 'From' value. Should the -f and the domain email address be in separate quotation marks? At the moment I have: mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders, '-f info@companyx.co.uk'); Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 no they should be in the same quotes. It shouldn't be changing the From but should change the Envelope from address. Try sending something basic for testing. may make the testing easier. Quote Link to comment Share on other sites More sharing options...
Joe Cool Posted December 2, 2009 Author Share Posted December 2, 2009 I've tested the form a few times with your suggested changes. However, I'm still getting the same results I did before. The 'From' email address in my inbox is always the email address the user enters in the 'email' field of the contact form. The problem is certain email addresses are being flagged as spam and are being blocked. If you put something like "jimsmith@test.com" into the email field and submit it, the enquiry goes through no problem. The enquiry comes through with the designated heading "Mortgage call back request from Company x". The from header in the email says "jimsmith@test.com". If you enter "jimsmith@yahoo.co.uk" into the email field and submit it, the enquiry doesn't go through. Certain email addresses are going through but Yahoo, Hotmail, Google, AOL and Fsnet addresses are being flagged as spam and are blocked. There may be another line that has to be added to the code somewhere. Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 Can you verify that the -f is working by sending an email to yourself with From set to your email then after the -f add an x to the front of your email address. Then see if the email you get has x<your emal> as its Envelope Sender address. Quote Link to comment Share on other sites More sharing options...
Joe Cool Posted December 2, 2009 Author Share Posted December 2, 2009 First Test I filled in the contact form and entered "info@companyx.co.uk" as my email address. I received the enquiry. The From value was "info@companyx.co.uk" Second Test I changed the line of code to: mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders, '-f xinfo@companyx.co.uk'); I filled in the contact form and entered "info@company.co.uk" as my email address. I received the enquiry. The From value was still "info@company.co.uk" There were no <> tags wrapped round the email addresses in either email. Quote Link to comment Share on other sites More sharing options...
Joe Cool Posted December 3, 2009 Author Share Posted December 3, 2009 I managed to figure it out. I tried numerous variations of the '-f' parameter without any success. I think most of the code Easyspace posted on their site, which I quoted in my first post is either inaccurate or unnecessary. The '-f' parameter turned out to be a red herring. I created a variable called $SendEmail. The value was: $SendEmail ="info@companyx.co.uk"; I removed the line: $mailheaders .= "Reply-To:$email\n"; I altered the line: $mailheaders = "From:$email\n"; I changed it to: $mailheaders = "From:$SendEmail\n"; The mail function stayed as it was: mail("info@companyx.co.uk",$subject,$sendemail,$mailheaders); After rigorously testing all contact forms on the site, these changes seem to have worked. Every email address I tried is now coming through without any problem. Including Yahoo, Hotmail, Google, AOL and FSnet email addresses. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.