Send form to different email addresses

Hi, first of all im new to this forum so hello to everyone.

I am having a few issues with trying to setup sending a from to different email addresses depending on a selection field. We have several clubs and I would like to use the same booking form for all of them, but just send to the relevant club depending on the customers location selection.

I have bought the theme from themeforst and have had no luck with the developers getting back to me on this.

I can post both form and php if it helps.

Thanks in advanced

Well, normally if it is an email system with various clubs to send to, you would have the clubs
showing in a drop-down so the user can select them. Or, sometimes, you might have the in a
list of check-boxes so the user can send the email to several clubs.

Either way, you pull the email option from the posted form data. For a drop-down, it would
look like:

Club Ernie
Club Nightlife
</select

So, in the PHP code, you would pull this value using $clubname=$_POST[‘club_name’];
Then, in the email you would use $clubname as the email address.

Should be simple enough. Now with that said, templates are sometimes tricky. They give you just
enough code and options to get you started and then either you learn all about the template or pay
them for services to fix it up. I bet we can help you.

If this info doesn’t help you solve it, then let us know something about how the list of clubs are displayed
to the user and how that is linked to the email addresses. I showed you the easy way. But, in templates,
quite often, they are tied to a database and you have to pull the email address from there.

Hi Ernie,

Thanks for your help, but think I may need to try something else as that did not work.

I am going to use a drop down to select the club.

the form looks like this…

			<div class="row">
				<div class="form-group col-xs-12">
					<textarea class="form-control" rows="3" name="inputMessage" id="inputMessage" placeholder="occation / message"></textarea>
				</div>
			</div>
            
          <div class="row">
          		<div class="form-group col-xs-12 col-sm-4">
                <label for="inputNumber">Number Of People?</label>
                <input type="text" class="form-control" name="inputNumber" id="inputNumber" placeholder="number" required>
              </div>
              
              <div class="form-group col-xs-12 col-sm-4">
                <label for="inputClub">Which Club?</label>
                  <select class="form-control" name="inputClub" id="inputClub">
                  	<option value="bournemouth">Bournemouth</option>
                    	<option value="cardiff">Cardiff</option>
                     <option value="London">London (City Road)</option>
                     <option value="Newcastle">Newcastle</option>
                    	<option value="Southampton">Southampton</option>
                     <option value="Blue Velvet">Blue Velvet</option>
                     <option value="Diamonds Club">Diamonds Club</option>
                  </select>
                </div>
                
                <div class="form-group col-xs-12 col-sm-4">
                  <label for="inputDate">Date?</label>  
               	<input name="inputDate" type="text" class="form-control" id="inputDate" />
                    
                </div>
          </div>
            
			<div class="row">
				<div class="form-group col-xs-12">
					<input id="num1" class="sum form-control" type="text" name="num1" value="" readonly />
					+
					<input id="num2" class="sum form-control" type="text" name="num2" value="" readonly />
					=
					<input id="captcha" class="captcha form-control" type="text" name="captcha" maxlength="2" />
					<span>(Are you human, or spambot?)</span>
				</div>
			</div>

			<div class="row">
				<div class="dt-form-info col-sm-6">
					<p>Once your booking has been made a member of our team will contact you with confirmation.</p>
				</div>
				<div class="form-group col-xs-12 col-sm-6">
					<button type="submit" class="btn-send">Make Booking</button>	
					<div class="success"><div class="icon-ok-5">Email sent !</div></div>
					<div class="fail"><div class="icon-attention">Failed to send Email !</div></div>
				</div>
			</div>

		</form>

And the php like this…

<?php $targetemail = "[email protected]"; //$targetemail = '[email protected]'; $name = $_POST['inputFullname']; $email = $_POST['inputEmail']; $phone = $_POST['inputPhone']; $message = $_POST['inputMessage']; $number = $_POST['inputNumber']; $club = $_POST['inputClub']; $date = $_POST['inputDate']; $num1 = isset($_POST['num1']) ? $_POST['num1'] : ""; $num2 = isset($_POST['num2']) ? $_POST['num2'] : ""; $total = isset($_POST['captcha']) ? $_POST['captcha'] : ""; $captcha_error = captcha_validation($num1, $num2, $total); if (is_null($captcha_error)) { $fullmessage = 'Name : ' . $name . '
' .'
'. 'Email : ' . $email . '
' .'
'. 'Phone : ' . $phone . '
' .'
'. 'Message : ' . $message . '
' .'
'. 'Number : ' . $number . '
' .'
'. 'Club : ' . $club . '
' .'
'. 'Date : ' . $date . '
'; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: <' . $email . '>' . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send email mail($targetemail, "Booking from " .$email, $fullmessage, $headers); } function captcha_validation($num1, $num2, $total) { global $error; //Captcha check - $num1 + $num = $total if( intval($num1) + intval($num2) == intval($total) ) { $error = null; } else { $error = "Captcha value is wrong."; } return $error; } ?>

Once again, thanks for your help!!!

First, next time, please post your code inside of the PHP tags so we can copy it easier.
To do that, you press the PHP button above where you are writing and place the code between
the two tags. insert-code-here Makes it much easier and faster for us. THanks.
(Oh, and put separate files in separate tags.)

Now, most of your code appears correct. How did you debug it so far? I feel I just covered this
for someone else in another thread, but, didn’t note the thread number.

So, we can help you. Which part is failing? To DEBUG this, the first thing would be to go down the
PHP file and see if you are getting all of the parts of the email inputs. First, I assume you changed
the $target_email variable to your email. Next, are you getting your data from the posted fields?
To debug this part, you can take a line like:
$email = $_POST[‘inputEmail’]; and add this this line under it:
die($email);
This will stop the program at that point and display the contents inside of the variable $email.
Showing you what is being pulled in at each step will allow you to see if one part is bad. Once you
are sure your data is all there, you debug the “flow” of the rest of your routines by sticking in a line
that tells you where you are, like: die("Got here !!! "); So, you can place that just inside the IF for
the is_null(captcha… and if you do not get a “Got here !!!”, then it might be the captcha routine.

SO, there are some debug ideas to start with. Let us know where it is breaking and we can help.

Hi,

sorry about that will put the php in tags from now on.

Yes, i changed the email address to mine and it sends fine.

When I try to replace the $targetmail to $club, it says ‘Email Sent’ but does not come through.

this is how is have done it…

[php]

<?php $targetemail = '$club'; $name = $_POST['inputFullname']; $email = $_POST['inputEmail']; $phone = $_POST['inputPhone']; $message = $_POST['inputMessage']; $number = $_POST['inputNumber']; $club = $_POST['inputClub']; $date = $_POST['inputDate']; $num1 = isset($_POST['num1']) ? $_POST['num1'] : ""; $num2 = isset($_POST['num2']) ? $_POST['num2'] : ""; $total = isset($_POST['captcha']) ? $_POST['captcha'] : ""; $captcha_error = captcha_validation($num1, $num2, $total); if (is_null($captcha_error)) { $fullmessage = 'Name : ' . $name . '
' . 'Email : ' . $email . '
' . 'Phone : ' . $phone . '
' . 'Message : ' . $message . '
' . 'No of People : ' . $number . '
' . 'Club : ' . $club . '
' . 'Date : ' . $date . '
'; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: <' . $email . '>' . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send email mail($targetemail, "Contact from " .$email, $fullmessage, $headers); } function captcha_validation($num1, $num2, $total) { global $error; //Captcha check - $num1 + $num = $total if( intval($num1) + intval($num2) == intval($total) ) { $error = null; } else { $error = "Captcha value is wrong."; } return $error; } ?>

[/php]

I tried the die($email); but nothing would send.

I have the form setup like you said…

Club 1 Club 2

Thanks for your help.

Let’s assume your “Captcha” code is working correctly. But, it looks like you are sending your email
to a “$to” which you call “$targetemail” from a variable $club which is not loaded before you use it.
The first line is $targetemail = $club ! But, $club is not defined at that point. So, it never sends out
to anyone.

So to DEBUG this, you need to display all of the data going into that function and see if it is in error.
So, replace this code:
[php]
//send email
mail($targetemail, "Contact from " .$email, $fullmessage, $headers);
[/php]
With this version:
[php]
echo “to=” . $targetemail . “

”;
echo “subject=” . "Contact from " . $email . “

”;
echo “message=” . $fullmessage . “

”;
echo “headers=” . $headers . “

”;
die(“above is email info…”);
//send email
mail($targetemail, "Contact from " .$email, $fullmessage, $headers);
[/php]
Run the email routine. It will print out exactly what you are trying to send to the “mail” function.
One of them is most likely incorrect. If everything looks correct them remove these added lines and
remove the “Captcha” code and see if the mail goes thru. My guess is one of these is formatted badly.

But, I bet it is sending out to nobody… Good luck and let us know…

Sponsor our Newsletter | Privacy Policy | Terms of Service