Welcome to WebmasterWorld Guest from 35.171.45.91

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

email to based on subject

     
12:53 am on Nov 22, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


I have a contact script that works but now I'm trying to figure out how to get it to email a specific address based on the subject chosen. This is what I have so far but it is not working as wanted
#######################################
<?php
if(isset($_POST['submit_form'])) {

# Default error_header
$error_header = "<p>Please check below for the errors that have occured, Pease be sure to include the missing fields indicated before continueing</p><br>";

# error checking
if(!$_POST['name']) {
$error1 = '<p>Please Fill in the Name field</p>';
} /*check to make sure name is filled in, if not display error message on form as error1*/
if(!$_POST['email']) {
$error2 = '<p>Please fill in the email field</p>';
} /*check to make sure email is filled in, if not display error message on form as error2*/

if(!$_POST['request']) {
$error3 = '<p>Please fill in your request or comments</p>';
} /*check to make sure a suggestion is filled in, if not display error message on form as error3*/
if ($_POST['department'] == 'none') {
$error4 = '<p>Please select an area you would like to comment on<p/>';
}

if ($_POST['contactrequested'] == 1) $contactrequested = "Please contact me";

if(!$error1 &&!$error2 &&!$error3 &&!$error4)

$subjects = array(
"request",
"missy",
"cds",
"bookings",
"coments",
"web-site",
"fan-club"
);

$toaddresses = array(
"csd@mysite.com",
"missy@mysite.com",
"orders@mysite.com",
"missy@mysite.com",
"csd@mysite.com",
"pat@mysite.com",
"dee@mysite.com"

);

$toaddress = 'pat@mysite.com'; //default email

$subject = $_POST["messagetype"];
for($i=0; $i<count($subjects); $i++){
if(strcasecmp($subject,$subjects[$i])==0){
$toaddress = $toaddresses[$i];
break;
}
}

$mailcontent = 'Customer name: '.$name."\n"
.'Customer email: '.$email."\n"
.'Contact requested: '.$contactrequested."\n"
.'Department: '.$department."\n"
."Customer requests or comments: \n".$request."\n";

#$fromaddress = 'From: [email]contacts@mysite.com[/email]';
$fromaddress = 'contacts@mysite.com';
$sent = @mail($toaddress,$subject,$mailcontent,"From: Contact <$fromaddress>\r\n");

?>
<?php
require ('./inc/header.inc.php');
?>
#############################
the rest of the page is the html form. can anyone offer any suggestions on why this is not working
Pat

9:08 am on Nov 22, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Give each of your subjects a value corresponding to the array slots, then access that slot:


<select name="dept">
<option value="0">Requests</option>
<option value="1">Missy</option>
<option value="2">CDs</option>
<option value="3">Bookings</option>
<option value="4">Comments</option>
<option value="5">Web-Site</option>
<option value="6">Fan Club</option>
</select>

Then when you process simply access the array slot.

$dept = $_POST['dept'];

mail($toaddresses[$dept],$subjects[$dept],$mailcontent,"From: Contact <$fromaddress>\r\n");

Hope that helps,

dc

10:56 am on Nov 22, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


DC, do the options have to be numbered or can they be named like
<option value="requests">Requests</option>
<option value="missy">Missy</option>
<option value="cds">CDs</option>
<option value="bookings">Bookings</option>
<option value="4">Comments</option>
<option value="5">Web-Site</option>
<option value="6">Fan Club</option>
Thanks for the help on this
Pat
12:54 pm on Nov 22, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


You`ll need to add key value pairs to your arrays if you want to use text descriptions. For example:

$toaddresses = array(
"cds" => "csd@mysite.com",
"missy" => "missy@mysite.com",
"support" => "support@mysite.com"
);

Then access the arrays the same way.

dc

1:03 am on Nov 23, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


Thanks Dreamcatcher, I already have a menu on the form called department so it will be easier to just use it instead of subject. I will just modify some of the code for department instead of subject
I will keep u posted on how it goes. This sure will make things easier for me.
Pat
8:37 am on Nov 23, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Sure thing Pat, no problem. Come back if you have any problems.

dc

1:52 pm on Nov 24, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


parse error. here is what I have so far and am getting the unexpected $ on line 177 there or about. The only this near there is the end of the page
#####################
PHP
<?php
session_start();
$name=$_POST['name'];
$_SESSION['name'] = $name;
?>
<?php
if(isset($_POST['submit_form'])) {

# Default error_header
$error_header = "<p>Please check below for the errors that have occured, Pease be sure to include the missing fields indicated before continueing</p><br>";

# error checking
if(!$_POST['name']) {
$error1 = '<p>Please Fill in the Name field</p>';
} /*check to make sure name is filled in, if not display error message on form as error1*/
if(!$_POST['email']) {
$error2 = '<p>Please fill in the email field</p>';
} /*check to make sure email is filled in, if not display error message on form as error2*/

if(!$_POST['request']) {
$error3 = '<p>Please fill in your request or comments</p>';
} /*check to make sure a suggestion is filled in, if not display error message on form as error3*/
if ($_POST['department'] == 'none') {
$error4 = '<p>Please select an area you would like to comment on<p/>';
}

if ($_POST['contactrequested'] == 1) $contactrequested = "Please contact me";

if(!$error1 &&!$error2 &&!$error3 &&!$error4)

$department = array(
"missy",
"sales",
"bookings",
"customer_service",
"fan_club"
);

$toaddresses = array(
"missy"=> "missy@mysite.com",
"sales"=> "orders@mysite.com",
"bookings"=> "missy@mysite.com",
"customer_service"=> "csd@mysite.com",
"fan_club"=> "dee@mysite.com"
);

$toaddress = 'pat@mysite.com'; //default email

$subject = $_POST["messagetype"];
$dept = $_POST['department'];

$mailcontent = 'Customer name: '.$name."\n"
.'Customer email: '.$email."\n"
.'Contact requested: '.$contactrequested."\n"
.'Department: '.$dept."\n"
."Customer requests or comments: \n".$request."\n";

$fromaddress = 'contacts@mysite.com';
mail($toaddresses[$dept],$department[$dept],$mailcontent,"From: Contact <$fromaddress>\r\n");

?>
<?php
require ('./inc/header.inc.php');
?>
#######################
HTML part of the form
<fieldset class="department"><label class="department" for="department">
<p>Please help us direct your feedback by selecting a catagory you would
like to comment on?</p>
<p><? echo "<font color='red'>$error4</font>";?></p>
<select id="department" name="department" size="1">
<option value="none">Select a Department</option>
<option value="missy">Missy</option>
<option value="sales">Sales</option>
<option value="bookings">Bookings</option>
<option value="customer_service">Customer Service</option>
<option value="fan_club">Fan Club</option>
</select></label>
<br>
</fieldset>
#################################
Can anyone see what i'm missing
Pat

2:31 pm on Nov 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2004
posts:933
votes: 0


It must a bracket missing.

I checked and I think that you forgot to close the first if statement

if(isset($_POST['submit_form'])) {

Also, try to always put brackets after the if statement, easier to debug afterwards
Therefore,

if ($_POST['contactrequested'] == 1) $contactrequested = "Please contact me";

should be
if ($_POST['contactrequested'] == 1) {$contactrequested = "Please contact me";}

Same problem occurs after

if(!$error1 &&!$error2 &&!$error3 &&!$error4)
3:00 pm on Nov 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Yep, tomda`s advice is good. Check your braces. You might want to think about getting a text editor that does brace matching.

dc

3:08 pm on Nov 24, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


Stll the same thing. I dont follow you one this one though
Same problem occurs after if(!$error1 &&!$error2 &&!$error3 &&!$error4)
I did put this
if(isset($_POST['submit_form']))
{
closing bracket here though
mail($toaddresses[$dept],$department[$dept],$mailcontent,"From: Contact <$fromaddress>\r\n");
}
?>
and the contactrequested brackets in. Im still getting the same parse error though. Any other suggestions one what may be missing of there and should not be there
Pat
3:20 pm on Nov 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


With your original code, just add a } after:

mail($toaddresses[$dept],$department[$dept],$mailcontent,"From: Contact <$fromaddress>\r\n");

dc

3:23 pm on Nov 24, 2005 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts:4449
votes: 11


It seems that you are missing the "Whole encompassing"
bracket
Try adding
a closing braket
after the last PHP chunck
where it reads
require....Header...
}
3:23 pm on Nov 24, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


can u Recommend a good text editor that does brace matching?
Pat
3:27 pm on Nov 24, 2005 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts:4449
votes: 11


that should do it
I do not get any error

I use UE, Ultra edit since many years

<last added/>
if you use Red Hat 8 or 9 on your local machine
it comes with a great PHP editor named Quanta

4:09 pm on Nov 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Or try Crimson Editor. Its a freebie. A lot of good text editors have brace matching.

Good luck.

4:51 pm on Nov 24, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


Thank-you every one i finally got it working. Part of the problem is i was uploading the one dir and testing in another so i was getting the same error over and over because i did not replace the bad file. I also had to remove the error testing for now as it would not work. I will now work on that part. The last thing i had to do was revise the mail(line to this
mail($toaddresses[$dept],$subject,$mailcontent,"From: Contact <$fromaddress>\r\n");
How do u make the fromaddress a link like
[email]missy_contacts, $fromaddress[/email] so that missy_contacts takes on the from email link
Pat
5:25 pm on Nov 24, 2005 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts:4449
votes: 11


I am not sure to follow you
but if you want to make fromaddress "clickable"
you can use a concataination
$begin="<mailto:";
$end=">click</a>";
then the concat
$click=$begin.$fromaddress.$end;

is that what you are looking for?

5:33 pm on Nov 24, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 27, 2004
posts:276
votes: 0


yes sir thats what in looking for
but now im not sure why i need it the link would just come back to me anyway. LOL
Thanks though I will keep that in mind for later projects. Now to get the error checking worked out
Pat