PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old February 1st, 2011, 03:22 AM
SpursFan SpursFan is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 3 SpursFan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 33 sec
Reputation Power: 0
Simple contact form script now needs SMTP Authentication

I wonder if any helpful coder could please look at the simple contact form script below and revise it to work for SMTP authentication.

The script is a bit old but I use it on a few sites and now it will not work because server admins have insisted server uses authentication.

Thank you to anyone willing to have a look.

Code:
<table class="contactform">
  <tr>
    <td align="center">

<?php 
if (isset($_POST["op"]) && ($_POST["op"]=="send")) { 

/******** START OF CONFIG SECTION *******/
  $sendto  = "mail@address.com";
  $subject = "Any";
// Select if you want to check form for standard spam text
  $SpamCheck = "Y"; // Y or N
  $SpamReplaceText = "*content removed*";
// Error message prited if spam form attack found
$SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.
</font><br><b>Your IP Number of <b>".getenv("REMOTE_ADDR")."</b> has been logged.</b></p>";
/******** END OF CONFIG SECTION *******/


  $name = $HTTP_POST_VARS['name']; 
  $email = $HTTP_POST_VARS['email']; 
  $message = $HTTP_POST_VARS['message']; 
  $tele = $HTTP_POST_VARS['tele'];
  $headers = "From: $email\n";
  $headers . "MIME-Version: 1.0\n"
         . "Content-Transfer-Encoding: 7bit\n"
         . "Content-type: text/html;  charset = \"iso-8859-1\";\n\n";
if ($SpamCheck == "Y") {         
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();} 
if (preg_match("/http/i", "$tele")) {echo "$SpamErrorMessage"; exit();}

// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer 
  $pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string 
                            
  $name = preg_replace($pattern, "", $name); 
  $email = preg_replace($pattern, "", $email); 
  $message = preg_replace($pattern, "", $message); 
  $tele = preg_replace($pattern, "", $tele);
  	
// Check for the injected headers from the spammer attempt 
// This will replace the injection attempt text with the string you have set in the above config section
  $find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i"); 
  $email = preg_replace($find, "$SpamReplaceText", $email); 
  $name = preg_replace($find, "$SpamReplaceText", $name); 
  $message = preg_replace($find, "$SpamReplaceText", $message); 
  $tele = preg_replace($find, "$SpamReplaceText", $tele);
  
// Check to see if the fields contain any content we want to ban
 if(stristr($name, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($message, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
 if(stristr($tele, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 
 // Do a check on the send email and subject text
 if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
 if(stristr($subject, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
}
// Build the email body text
  $emailcontent = " 
----------------------------------------------------------------------------- 
   WEBSITE CONTACT ENQUIRY
----------------------------------------------------------------------------- 

Name: $name 
Email: $email 
Message: $message
Tel: $tele 

_______________________________________ 
End of Email 
"; 
// Check the email address enmtered matches the standard email address format
 if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) { 
  echo "<p>It appears you entered an invalid email address</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

 elseif (!trim($name)) { 
  echo "<p>Please go back and enter a Name</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 


 elseif (!trim($message)) { 
  echo "<p>Please go back and type a Message</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
}  

 elseif (!trim($email)) { 
  echo "<p>Please go back and enter an Email</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; 
} 

// Sends out the email or will output the error message 
 elseif (mail($sendto, $subject, $emailcontent, $headers)) { 
  echo "<br><br><p><b>Thank you for your enquiry $name</b></p><p>We will be in touch as soon as possible.</p>"; 

} 
} 
else { 
?> 
<p class="centerparagraph">Please complete the details of your enquiry and we will 
contact you shortly.</p>
<form method="post"><INPUT NAME="op" TYPE="hidden" VALUE="send"> 
  <table> 
    <tr> 
      <td><p class="contactform-righttxt">Name:</p></td> 
      <td> 
        <input name="name" type="text" size="30" maxlength="150"> 
      </td> 
    </tr> 
      <tr> 
      <td><p class="contactform-righttxt">E-mail:</p></td> 
      <td> 
        <input name="email" type="text" size="30" maxlength="150"> 
      </td> 
    </tr> 
    <tr> 
      <td><p class="contactform-righttxt">Tel No (Optional):</p></td> 
      <td> 
        <input name="tele" type="text" size="30" maxlength="25"> 
      </td> 
    </tr>
    <tr> 
      <td valign="top"><p class="contactform-righttxt">Message:</p></td> 
      <td><textarea name="message" cols="40" rows="6"></textarea></td> 
    </tr> 
    <tr><td></td> <td><input name="submit" type="submit" value="Send Message"></td></tr> 
  </table> 
</form> 
<?php } ?>

   </td>
  </tr>
</table>

Reply With Quote
Old February 1st, 2011, 03:58 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,439 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 47 m 34 sec
Reputation Power: 9
Quote:
Originally Posted by SpursFan
I wonder if any helpful coder could please look at the simple contact form script below and revise it to work for SMTP authentication.
[/code]


I dont think this forum is for people looking to get others to do the work for them, its for looking for help to solve problems...

http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

might prove of some use, if you have trouble Id be more than happy to help but i sure as hell wont write something for someone if they are looking to avoid doing the leg work themselves
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Reply With Quote
Old February 1st, 2011, 05:16 AM
SpursFan SpursFan is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 3 SpursFan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 33 sec
Reputation Power: 0
Apologies if I have given the wrong impression or posted in the wrong forum.

I would willingly do the leg work if PHP coding meant anything to me at all!
I have looked at the link you kindly provided (and ones I had previous Googled myself) and how all that gets integrated into the exisiting form which I dont think uses Pear, I would not know where to start.

My options would appear to be to pay a PHP programmer to work the code or rip out the script on the sites it is affecting and replace it with an authenticating one, however this invoves changes to the site and forms CSS.

As the old script above does not validate anyway, I think I will 'bite the bullet' and go for replacement.

Thank you for your quick response and apologies again.

Reply With Quote
Old February 1st, 2011, 05:56 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,439 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 47 m 34 sec
Reputation Power: 9
No worries, here is a link to a phpmailer script i use:

http://phpmailer.worxware.com/

and a tutorial can be found here

http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html

and here is a sample of the code i use on my site:

PHP Code:
 $from $_POST['txtEmail'];
$from_name $_POST['txtName'];
$subject $_POST['txtSubject'];
$message $_POST['txtQuery'];
if (empty(
$_POST['somefield']) or !isset( $_POST['somefield'])) $_POST['somefield'] = '-';
$subject "subject ";
require(
"class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
// $mail->Host = "127.0.0.1"; // SMTP server
$mail->Host "yourmail.mail.ie:25"// SMTP server    
$mail->SMTPAuth true;     // turn on SMTP authentication
// $mail->Username = "username";  // SMTP username
// $mail->Password = "password"; // SMTP password
$mail->CharSet  'UTF-8'
//$mail->IsHTML(true);  // set email format to HTML 
$mail->FromName $from_name;
$mail->From $from;
//$mail->AddAddress($to);
$mail->AddAddress("you@yourdomain.ie");
$mail->AddAddress($_POST['txtEmail']);
$mail->Subject $subject;
$mail->Body  $message;
$mail->WordWrap 50;

if(!
$mail->Send()) {
    echo 
"Your email has failed to send";

}
else {
    echo 
"Your email has been sent successfully";



Its actually not that complex, the mailer script does all the work for you

Last edited by DavidMR : February 1st, 2011 at 05:58 AM.

Reply With Quote
Old February 1st, 2011, 08:59 AM
SpursFan SpursFan is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 3 SpursFan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 33 sec
Reputation Power: 0
Thank you for the links and the code - most helpful.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Simple contact form script now needs SMTP Authentication


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap