Jump to content

Send email to address based on text choice


blepblep

Recommended Posts

Hi, wondering could anyone help me here again. I have been asked to implement a email feature depending on a selection. I've seen plenty of examples online about doing it from a drop down, but I need to do it without a drop down menu.

 

The user has 9 forms to choose from. Each of these forms has a name, say TC CNOSS, TC OSS RC etc for example (These forms are selected from a drop down menu but this drop down menu is not populated from the database, it is hard coded). When the user fills in a form, they get an ID which they enter to a search menu. This returns the form they filled in, but with a small bit of extra information needing to be filled in. After they fill in this extra bit of information, I have a button that says 'Send to X for approval'. This button goes to another page which performs the below code -

 

Now the part I am stuck at is, how do I send an email to say TC CNOSS if the user is filling in a form of TC CNOSS? I just want the email to say 'TC Number 10 needs to be approved' and then include a link to my site.

 

<?php

$reviewForum = $post['reviewForum'];

if(isset($_POST['submit']))
{
if ($post['reviewForum'] = 'TC CNOSS') {

// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('testemail@test.com', 'My Subject', $message);

}
}
?>

 

Thanks to anyone who can help, if there is any more info needed just ask.

Link to comment
Share on other sites

Not quite sure what your looking to do here, but the first thing I noticed in the code was that there was only one '=' sign meaning the if statement is always true. Also why did you set the variable of the post value and then use the post variable in the if statement?

Link to comment
Share on other sites

What I want to do is to send an email to an address based on a forum. There is 9 forums to choose from in a drop down menu but these are hard coded in. Sorry I shouldn't have set the variable of the post outside the if statement. My bad sorry!

 

I dont no how I can send an email based on a certain form that the user selects.

Link to comment
Share on other sites

This was the original idea I had in my head as to how I was going to code it but it doesnt work -

 

$email_location = $_POST['location']; // the value from your form

if($email_location == "Atlanta") { // a form value and a location
    $your_email = "atlanta@email.com"; // the email for that location
} else if ($email_location == "Colorado") {
    $your_email = "colorado@email.com";
} else if ($email_location == "Virginia") {
    $your_email = "virginia@email.com";
} else if ($email_location == "Kansas City") {
    $your_email = "kansas@email.com";
} else { // if no one is good, send it to this email
    $your_email = "standard@email.com";
}

Link to comment
Share on other sites

What does your form code look like?

 

It is incredibly messy, the first half of it was coded by myself and the second by someone else. Heres a snippet of mine with the code getting the reviewForum. The reviewForum is what I want to send the email to, so instead of having a drop down menu that contains the 9 forums, I just want to have some sort of condition that checks if it is TC CNOSS send an email to tcnoss@email.com, if it is TC TOR send an email to tctor@email.com etc etc.. Is this possible do you think?

 

<tr>
	<th>Review Forum</th>

</tr>		
	<td>"	.	custOut($row['reviewForum'])	.	"</td>

 

24bogif.jpg

 

My button code -

<td>
<form id='sendEmail' action = \"sendMomEmail.php\" method = \"post\">
	<input type = \"submit\" value = \"Send email for approval\" style='display:inline;' onclick =\"sendMomEmail.php\">
</form>	
</td>

Link to comment
Share on other sites

Instead of forms, could you links?

 

<tr><th>Review Forum</th><th>Review ID</th><th>Send E-mail</th></tr>
<tr><td>TC CNOSS</td><td>TC19</td><td><a href="sendMomEmail.php?sendemail=TCCNOSS">Send e-mail to TC CNOSS</a></td></tr>

 

 

The links could be processed with a switch():

 

<?php
switch($_GET['sendemail']) {
case 'TCCNOSS':
	$toEmail = 'TCCNOSS@test.com';
	break;
}

// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

mail($toEmail, 'My Subject', $message);
?>

Link to comment
Share on other sites

Instead of forms, could you links?

 

<tr><th>Review Forum</th><th>Review ID</th><th>Send E-mail</th></tr>
<tr><td>TC CNOSS</td><td>TC19</td><td><a href="sendMomEmail.php?sendemail=TCCNOSS">Send e-mail to TC CNOSS</a></td></tr>

 

 

The links could be processed with a switch():

 

<?php
switch($_GET['sendemail']) {
case 'TCCNOSS':
	$toEmail = 'TCCNOSS@test.com';
	break;
}

// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

mail($toEmail, 'My Subject', $message);
?>

 

I can't use links like that. The Review Forum and Review ID I posted in the screenshot from search result so they are different each time.

 

Could you explain this to me please -

 

<td><a href="sendMomEmail.php?sendemail=TCCNOSS">Send e-mail to TC CNOSS</a></td></tr>

 

How will the above work if it is a different forum to TC CNOSS? As there is 9 possible ones and I don't no how that would work with the

sendemail = TCCNOSS

part?

 

These are the different forums - TC CNOSS, TC PM, TC OSS RC, TC Arch Board,  TC TOR, TC PF, TC WRAN, TC GRAN, TC Navigator.  I am wondering how could I do it the way you described but instead of naming the link TC CNOSS as this could be different depending on what Review Forum it is..

Link to comment
Share on other sites

Basically, you would create however many links you would need:

 

<tr><th>Review Forum</th><th>Review ID</th><th>Send E-mail</th></tr>
<tr><td>Forum 1</td><td>...</td><td><a href="sendMomEmail.php?sendemail=forum1">Send e-mail to Forum 1</a></td></tr>
<tr><td>Forum 2</td><td>...</td><td><a href="sendMomEmail.php?sendemail=forum2">Send e-mail to Forum 2</a></td></tr>
<tr><td>Forum 3</td><td>...</td><td><a href="sendMomEmail.php?sendemail=forum3">Send e-mail to Forum 3</a></td></tr>

 

 

Note that the "Send e-mail to Forum 1" could say anything you want. It could also be an image that looks like a button.

 

 

Here is one way to process the above links:

 

<?php
switch($_GET['sendemail']) {
case 'forum1':
	$toEmail = 'email1@test.com';
	break;
case 'forum2':
	$toEmail = 'email2@test.com';
	break;
case 'forum3':
	$toEmail = 'email3@test.com';
	break;
}

// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

mail($toEmail, 'My Subject', $message);
?>

Link to comment
Share on other sites

Ahhh ok, I see what you mean. Thanks for that. Is there a way I can do it like this?

 

15367wg.jpg

 

And then, depending on what is selected, send an email to that address?

 

Am I wrong in saying how you have it done for me, it will display 3 links that I can click on each time, so instead of just showing one link it will show however many is created?

Link to comment
Share on other sites

The code is pretty much the same, you're just dealing with a POST variable versus GET. For a drop down that looks like the following:

 

<form method="post" action="sendMomEmail.php">
<select name="selectDept">
<option value="">Please Choose Dept.</option>
<option value="TC OSS RC">TC OSS RC</option>
<option value="TC OSS Arch Board">TC OSS Arch Board</option>
</select>
<input type="submit" value="Send email for approval">
</form>

 

 

The switch() could be modified to

 

<?php
switch($_POST['selectDept']) {
case 'TC OSS RC':
	$toEmail = 'TCOSSRC@test.com';
	break;
case 'TC OSS Arch Board':
	$toEmail = 'TCOSSArchBoard@test.com';
	break;
}

// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

mail($toEmail, 'My Subject', $message);
?>

Link to comment
Share on other sites

Am I wrong in saying how you have it done for me, it will display 3 links that I can click on each time, so instead of just showing one link it will show however many is created?

 

That is correct. The link version of the code will show 3 links (or however many links are created).

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.