logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-14-2012, 03:41 AM   #1
tahsin1982
 
Join Date: May 2011
Location: Canada
Posts: 50
Default Contact From PHP problem

Hi guys,

Sorry if this has been asked before, I am not really that good in PHP and was building a contact for with this scrip I found on the net

PHP Code:
<?php

// Set email variables
$email_to 'xxxxx@xxxx.com';
$email_subject 'Form submission';

// Set required fields
$required_fields = array('fullname','email','comment');

// set error messages
$error_messages = array(
    
'fullname' => 'Please enter a Name to proceed.',
    
'email' => 'Please enter a valid Email Address.',
    
'comment' => 'Please enter your Message.'
);

// 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 'New Website Comment: ' "\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 script is great and works perfect on the website but the problem I notice is when I test the form and press submit and check it on my inbox.

The Receiver address shows my email address with my webhost address (not the urname@domain.com) rather than the original senders add. Only if I open the message I can see the senders email address in the email field but thats about it.

I am not sure how to fix this but if anyone has any tips would be very helpful as I really like this script.

cheers
tahsin1982 is offline   Reply With Quote
Old 04-14-2012, 04:11 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

it shows that because thats where its being sent from. perhaps you could add it to the subject line if you wanted,
Code:
to do that move $email_subject = 'Form submission';

to

 // simple email content
        foreach($_POST as $key => $value) {
            if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
        }

$email_subject = 'Form submission from ' .$_POST['email'];
        
        // if validation passed ok then send the email
        mail($email_to, $email_subject, $email_content);
not tested but should be ok
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 04-14-2012, 04:50 AM   #3
tahsin1982
 
Join Date: May 2011
Location: Canada
Posts: 50
Default

Hi thanks for replying I tried it but didnt work. Still showing the senders email add as my own hosting email add. The subject is displaying fine its just the senders name dosent show up in the box but my domain email add. I am stumped...
tahsin1982 is offline   Reply With Quote
Old 04-14-2012, 09:34 AM   #4
tahsin1982
 
Join Date: May 2011
Location: Canada
Posts: 50
Default

Ok this is getting confusing and fraustrating. I think my cache in my server or something is not really updating changes I make to the php script. Even when I change the
PHP Code:
// Set email variables
$email_to 'xxxxx@xxxx.com'
$email_subject 'Form submission'
example to a different email address. Its still sending email address to the old one and nothing to my new one.

I even redownloaded the updated php files to make sure whether the codes are updated and they are but somemore i think cache or something is messed.

I better email my hosting provider about this.
tahsin1982 is offline   Reply With Quote
Old 04-14-2012, 04:54 PM   #5
tahsin1982
 
Join Date: May 2011
Location: Canada
Posts: 50
Default

I got it fixed

PHP Code:
// simple email content
        
foreach($_POST as $key => $value) {
            if(
$key != 'submit'$email_content .= $key ': ' $value "\n";
        }
        
        
$email_subject 'Form submission from ' .$_POST['email'];
        
        
$email_headers "From: " $_POST['email'] . "\n" "Return-Path: " $_POST['email'] . "\n" "Reply-To: " $_POST['email'] . "\n";
        
        
// if validation passed ok then send the email
        
        
        
mail($email_to$email_subject$email_content$email_headers); 
The header was the part I needed to declare so now its working thanks again ED for the telling where to put the code.

cheers
tahsin1982 is offline   Reply With Quote
Reply


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


All times are GMT. The time now is 10:37 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com