Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 14th February 2011, 19:22
newagekat newagekat is offline
Junior Member
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question redirect mail based on subject line

Hello:

I just joined so still wet behind the ears. I can read and tweak code, but I'm no programmer.

I've been using a PHP script to create a contact form, display a message on Send and to send html email.

script begins with:
Code:
<?
            function SafeHTML($string) {
	        $string = stripslashes($string);
	        $string = htmlspecialchars($string);
	        return nl2br($string);
            }
            function ValidateEmail($Email){
	        $result = ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $Email);
	        if ($result){
		    return true;
	        } else {
		    return false;
            }
            }
            $subject = $_POST['subject'];
            $subject = SafeHTML($subject);
            $name = $_POST['name'];
            $name = SafeHTML($name);
            $email = $_POST['email'];
            $telephone = $_POST['telephone'];
            $telephone = SafeHTML($telephone);
            $message = $_POST['message'];
            $message = SafeHTML($message);
            $contact = $_POST['contact'];
            $contact = SafeHTML($contact);

            switch($_GET[action]) {
	        case "check";
	        if(strlen($subject) > 0 && strlen($name) > 0 && strlen($telephone) > 0 && strlen($email) > 0 && strlen($message) > 0 && !strstr($message, "http") && !strstr($message, "href") && ValidateEmail($email) == true) {
		    $body=
followed with html email format

then
Code:
;
		    $headers = "From: $name <$email>\r\n";
		    $headers.="Content-type: text/html\r\n";
		    mail("client name <client@somedomain.com>","New email from your website",$body, $headers);
		    print "<div class='thanks'><p>Thank you for your email, <strong>$name</strong>.</p>
		    </div>";	
            } else {
 	        print "<p class='star'><strong>You did not fill out all the required fields ( marked with * ) or you have entered an invalid email address. Please check the form and resubmit</strong></p>";
	            include("contactform.php");
            }
 	        break;
	        default:
		        include("contactform.php");
	        break;
            }
            ?>
How do I add a conditional statement in the $headers mail part to redirect mail based subject?

Any assistance is much appreciated. thank you.
kp
Reply With Quote
Sponsored Links
  #2  
Old 15th February 2011, 15:47
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,751 Times in 2,581 Posts
Default

Do you mean something like this?

PHP Code:
if(stristr($subject'blabla') === FALSE) {
    
// string not found in subject
    
$headers = ...;
} else {
   
// string found in subject
   
$headers = ...;

__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 17th February 2011, 01:20
newagekat newagekat is offline
Junior Member
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default edirect mail based on subject line

Thank you so much for replying.

Actually, falko, the subject will be a drop down, but of the the options is for solicitation. if chosen, i want the email to go to my junk folder immediately.

but maybe the code you provided can still work if i make the change below?

Code:
if(stristr($subject, 'blabla') === TRUE) {
    // string not found in subject
    $headers = <junk@domain.com>;
} else {
   // string found in subject
   $headers =  <client@domain.com>;
Reply With Quote
  #4  
Old 17th February 2011, 18:33
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,751 Times in 2,581 Posts
 
Default

Use
PHP Code:
if(stristr($subject'blabla') === TRUE) {
    
// string not found in subject
    
$to_address 'junk@domain.com';
} else {
   
// string found in subject
   
$to_address =  'client@domain.com';

and then pass $to_address as the first parameter to PHP's mail() function.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when install ISPConfig 2 with components built from source X-admin Installation/Configuration 5 30th April 2010 14:22
just the last step...and it works. Postfix...need help config. ubuntusr Installation/Configuration 1 5th January 2009 10:50
Bugs in the code of the ISPConfig software vaio1 Installation/Configuration 15 20th May 2008 11:32
ispconfig php 5 errors itamarjp Installation/Configuration 8 25th April 2008 11:20
Incoming Mail Deleted? Jammer4774 General 19 20th July 2007 23:06


All times are GMT +2. The time now is 09:11.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.