martinstan Posted August 26, 2008 Share Posted August 26, 2008 Hi I've been asked to do something on a simple contact form but I'm not sure how to do it. Hopefully someone can help. How can I set a form to always be from a particular email address. Here's the code I'm using: $to = "webenquiry@adomain.co.uk"; $name = $_POST['name']; $company = $_POST['company']; $tel = $_POST['tel']; $email = $_POST['email']; $msg = $_POST['msg']; $d = date('l dS \of F Y h:i:s A'); $sub = "Contact from website"; $headers = "From:" .$email."\n"; $mes .= "Name: ".$name."\n"; $mes .= "Company: ".$company."\n"; $mes .= "Tel No: ".$tel."\n"; $mes .= 'Email: '.$email."\n"; $mes .= "Message: ".$msg."\n"; I'm assuming it's something I need to change in the $headers = "From:" .$email."\n"; Can I just replace the variable $email to a fixed email address? The reason I've been asked to do this is because many of the email addresses that people use on the contact form are being filtered out by over zealous spam filters. Having the form saying it's from someone@fixed-email-address.co.uk would get them around this problem. Many Thanks Martin Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/ Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 Can I just replace the variable $email to a fixed email address? Yes, but some ISP's require it to be valid and on the same domain as the webhost. Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626112 Share on other sites More sharing options...
ThunderAI Posted August 26, 2008 Share Posted August 26, 2008 So you want the person filling out the forms email address to be a set email adress all the time reguardless of where it actually came from? I'm not sure if that can be done, but you can set the subject of an email to be something like COMMENT FROM WEB - (their comment). Then all you have to do is filter out emails with the subject COMMENT FROM WEB. Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626113 Share on other sites More sharing options...
martinstan Posted August 26, 2008 Author Share Posted August 26, 2008 Hi Guys Wow I really appreciate how quickly you've got back to me on this. I know it sounds odd and I'm not fully clear about it myself so apologies for the slightly vague interpretation. It's some 'Hardware' bloke who's asked me to do this. I think the idea is that the senders email address will still be collected by the form as part of the email body, but the 'from' field in the header will remain generic so that the spam filters will always recognise it as being safe. Would this work in principle: $headers = "From: "someone@fixed-email-address.co.uk "\n"; I can worry about the ISP issues later. Many thanks Martin Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626122 Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 Yes Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626125 Share on other sites More sharing options...
martinstan Posted August 26, 2008 Author Share Posted August 26, 2008 Cheers I'll give it a go! Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626133 Share on other sites More sharing options...
martinstan Posted August 26, 2008 Author Share Posted August 26, 2008 Well gave it a go and got the following error; Parse error: syntax error, unexpected '@' in /home/sites/domain.co.uk/public_html/process.php on line 25 line 25 being $headers = "From: ".someone@fixed-email-address.co.uk. "\n"; Just to clear things up I'm using valid email addresses in my actual coding. I'm just putting dummy ones in here for the purposes of the posting. $to = "webenquiry@adomain.co.uk"; $name = $_POST['name']; $company = $_POST['company']; $tel = $_POST['tel']; $email = $_POST['email']; $msg = $_POST['msg']; $d = date('l dS \of F Y h:i:s A'); $sub = "Contact from website"; $headers = "From: ".someone@fixed-email-address.co.uk. "\n"; $mes .= "Name: ".$name."\n"; $mes .= "Company: ".$company."\n"; $mes .= "Tel No: ".$tel."\n"; $mes .= 'Email: '.$email."\n"; $mes .= "Message: ".$msg."\n"; Is this an expected error with this and is my coding just wrong? Thanks Martin BTW I've checked with my ISP and they say they don't have a problem with me doing this. Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626174 Share on other sites More sharing options...
kenrbnsn Posted August 26, 2008 Share Posted August 26, 2008 Just put the whole address inside the quotes: <?php $headers = "From: someone@fixed-email-address.co.uk\n"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626177 Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 Yeah, you had extra quotes in there. Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626187 Share on other sites More sharing options...
martinstan Posted August 26, 2008 Author Share Posted August 26, 2008 I see. Yes it works! Not much of a programmer am I Thanks to all. Martin Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626198 Share on other sites More sharing options...
martinstan Posted August 26, 2008 Author Share Posted August 26, 2008 Hey I've just seen your donation thread too. Consider it done. Good forum and deserves some support. Quote Link to comment https://forums.phpfreaks.com/topic/121421-php-form-set-a-generic-from-address/#findComment-626207 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.