Jump to content

Get the Form to mail to two emails


Chrisj
 Share

Recommended Posts

The contact Form mails successfully to the $youremail part of this code,

but I'd like the message to also mail to the submitter's entered email address,

which I believe is: E-Mail: $_POST    I tried this without success:

 

<?php

// if the url field is empty
//if(isset($_POST['url']) && $_POST['url'] == '')
{

	$youremail = 'wcform@....com';
	$body = "UploadForm-M:
	Name:  $_POST[name]
	E-Mail: $_POST[email]
	Message: $_POST[message]";

	if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
	  $headers = "From: $_POST[email]";
	  $headers = "From: $youremail";
	}
	mail($youremail, 'Contact Form', $body, $headers );
	mail(email, 'Contact Form', $body, $headers );
}
if(empty($error))
{
header('Location: http://...com');
exit;
}
?>

Any additional help will be appreciated.

Edited by Chrisj
Link to comment
Share on other sites

Ok - so do you see what's wrong with this line?

	mail(email, 'Contact Form', $body, $headers ); } 
	

The word "email".  What is that actually?  If you had error checking turned on you probably would be seeing a message.  Actually, I'm surprised the script even runs with that in it.  (Must be defaulting to a constant that is not defined.)

You need a variable there or an actual string (text in quotes).

The better way might be to add your second address to the headers as a CC: which you could look up in the PHP manual.  That way you just have one email going out. (Or a BCC if you want to hide it)

 

 

Link to comment
Share on other sites

I'll be honest with you: this is not the sort of thing that should need an example.

ginerjm pointed out the line of code that needs fixing, and that the "email" bit is what's wrong. You already know that the email address you want is in $_POST (not literally $_POST but one of the values in it). So it should just be a matter of taking the bad thing out and putting the good thing in.

That should get you something that at least works correctly, however it may have a subtle flaw to it so I suggest posting what you end up with just in case.

Link to comment
Share on other sites

As Requinex says - make some changes and try it out and then show us what is failing.  I, for one, am not sure what kind of example you need since I only posted one line of your code and pointed out its weakness.

BTW - while it is allowed and does in fact work (although at an extra expense I'm sure) PHP will work more efficiently if you wrap your array indices in quotes.  An example of that is simply:

	$array['index']
	

 

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.