Jump to content

PHP form. Set a generic 'From' address


martinstan

Recommended Posts

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

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.