Page 1 of 2

multiple website emails, one form for customers for all emai

Posted: Wed Oct 25, 2006 9:48 am
by bufhal
Hello;
I hope someone can offer some help.
Our website has several email links to several departments. We are trying to get rid of them for spam purposes and offer a link to one form that the user will fill out (just subject and message) and upon submit, will go to prespective email in prespective department. We have 30-40 emails so a form for each one would not work.
Can someone offer an idea or premade code snippett that can solve our problem?
I appreciate any help.
Thank you in advance for your time.

Re: multiple website emails, one form for customers for all

Posted: Wed Oct 25, 2006 11:59 am
by hawleyjr
bufhal wrote:Hello;
I hope someone can offer some help.
Our website has several email links to several departments. We are trying to get rid of them for spam purposes and offer a link to one form that the user will fill out (just subject and message) and upon submit, will go to prespective email in prespective department. We have 30-40 emails so a form for each one would not work.
Can someone offer an idea or premade code snippett that can solve our problem?
I appreciate any help.
Thank you in advance for your time.
You have a few options. One option is to implement a CAPTCHA page.

You can also, do a drop down with a list of name (Don't list emails) and have the user select which person he/she is sending to.

The option you listed. "Have the form go to one email) is fairly simple.

Code: Select all

$send_to_email = 'info@example.com';
$send_from_email = $_POST['user_email'];//MAKE SURE YOU VALIDATE THIS EMAIL ADDRESS
$subject = $_POST['mssg_subj'];//MAKE SURE YOU CLEAN THIS INPUT
$body = $_POST['mssg_body'];//MAKE SURE YOU CLEAN THIS INPUT

//VALIDATE ALL FIELDS HERE

//SEND EMAIL
mail ( $send_to_email, $subject . ' From: ' . $send_from_email, $body  );
I want to point out that this is using the mail function in it's most simplistic form. There are other BETTER and MORE EFFECTIVE alternatives out there.

thank you

Posted: Wed Oct 25, 2006 1:17 pm
by bufhal
I appreciate your reply. I think the best way to do this is a list the outside user can choose from. I am not sure if all this can be achieved in one form.
You can also, do a drop down with a list of name (Don't list emails) and have the user select which person he/she is sending to.

Is there a working example you know of or can you please show me how my existing HTML page (below) can "send" to the different emails?
We have around 20 email names.

Code: Select all

<html>
<head><title>Mail sender</title></head>
<center>
<body bgcolor="#d0d0d0">


<hr><br><h2>Please email us...</h2>
<br><br>

<form action="mail2.php" method="POST">

<p><b>Subject</b><br>
<input type="text" name="subject" size=40>
<p><b>Message</b><br>
<textarea cols=40 rows=10 name="message"></textarea>
<p><input type="submit" value=" Send ">
</form>

</body></center>
</html> 
</code>


<?php

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$email = $HTTP_POST_VARS['email'];
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail("gzakes@attotech.com",$subject,$message)) {
  echo "<h3>Thank you for sending email</h3>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>

Posted: Wed Oct 25, 2006 1:27 pm
by John Cartwright
Create an array of the email addresses, alas..

Code: Select all

<?php 

$emails = array(
   'Technical Support' => 'tech@domain.com',
   'Sales and Inquiry' => 'sales@domain.com'
);

//validation of your form takes place here
//add checks to make sure ALL the values are valid.. 
//I've only done for for the email_to drop down

if (!empty($_POST['email_to']) && in_array($_POST['email_to'], $emails)) {

   if (mail( ... )) {
      echo 'Email sent'; 
      exit(); //redirect maybe?
   }
}

?>

<html>
<head><title>Mail sender</title></head>
<center>
<body bgcolor="#d0d0d0">

<hr><br>
<h2>Please email us...</h2>
<br><br>

<form action="mail2.php" method="POST">
   <p><b>Subject</b><br>
   <input type="text" name="subject" size=40>
   <select name="email_to">

<?php
   foreach ($emails as $department => $email) { 
      echo '<option value="'. $email.'">'.$department.'</option>';
   }
?>

<p><b>Message</b><br>
<textarea cols=40 rows=10 name="message"></textarea>
<p><input type="submit" value=" Send ">
</form>

</body></center>
</html>
</code>

Posted: Wed Oct 25, 2006 1:37 pm
by hawleyjr
Printing the email address in the select box will not stop bots from grabbing the email address....

Code: Select all

$emails = array(
   'Technical Support' => 'tech@domain.com',
   'Sales and Inquiry' => 'sales@domain.com'
);

   foreach ($emails as $department => $email) {
      echo '<option value="'. $email.'">'.$department.'</option>';
   }
To...

Code: Select all

$emails = array(
   1 => 'tech@domain.com',
   2 => 'sales@domain.com'
);
$email_labels = array(
   1 => 'Technical Support',
   2 => 'Sales and Inquiry'
);

   foreach ($email_labels as $ak=> $label) {
      echo '<option value="'. $ak.'">'.$label.'</option>';
   }

Thank for your help.

Posted: Wed Oct 25, 2006 2:09 pm
by bufhal
I will try to put this together and get it working. Thanks for your help and time.

Please take another look

Posted: Wed Oct 25, 2006 3:04 pm
by bufhal
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thank you for your help.
I am getting close, but this is not working.
I want the dropdown menu, when someone hits submit, to send the email(subject and message) to that person.
I appreciate your help.

Code: Select all

<?php 
$emails = array( 
   0 => 'et@email.com', 
   1 => 'jb@email.com' ,
   2 => 'rpec@email.com' ,
   3 => 'mkt@email.com' ,
  
); 
if (!empty($_POST['email_to']) && in_array($_POST['email_to'], $emails)) { 

   if (mail(  )) { 
      echo 'Email sent'; 
      exit(); 
   } 
} 
?><center> 
<body bgcolor="#d0d0d0"> 
<hr><br> 
<h2>Please email us...</h2> 
<br><br> 
<form action="mail2.php" method="POST"> 
   <p><b>Subject</b><br> 
   <input type="text" name="subject" size=50> 
   <br><br> 
   <select name="email_to"> 
	<option value="1">Ela Teirn -  Dir of Marketing</option> 
	<option value="2">Jen B -  Asia Sales</option> 
	<option value="3">Rick P -  Tech Support</option> 
	<option value="4">General Marketing Inquiry</option> 
	
	</select>
	<br><br>
<b>Message</b><br> 
<textarea cols=40 rows=10 name="message"></textarea>
<input type="submit" value=" Send "> 
</form>  </body></center> 
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

need the page link to fill in a email box on form

Posted: Thu Oct 26, 2006 1:08 pm
by bufhal
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


thank you for the info. Our company decided to switch tactics. Instead of a dropdown, they want this to work as follows. A person on a page of the site clicks on an email gif that contains the link to this form. The persons name will show in a box on this page (code below) and when the form is filled out and submitted it will go automatically to that email. I am somewhat stuck here. In addition to this code, the actual clickable gif needs to contain a variable to fill in the box on the form.
Please let me know how I can accomplsh this.
Thank you.

Code: Select all

<?php 
$emails = array( 
   0 => 'et@email.com', 
   1 => 'dd@email.com' ,
   2 => 'rpec@email.com' ,
   3 => 'mkt@email.com' ,
  
); 
if (!empty($_POST['email_to']) && in_array($_POST['email_to'], $emails)) { 

   if (mail(  )) { 
      echo 'Email sent'; 
      exit(); 
   } 
} 
?><center> 
<body> 

<h2>Please email us...</h2> 

<form action="mail2.php" method="POST"> 
   <p><b>Subject</b><br> 
   <input type="text" name="subject" size=50> 
   <br><br> 
   	<br><br>
<b>Message</b><br> 
<textarea cols=40 rows=10 name="message"></textarea>
<input type="submit" value=" Send "> 
</form></body></center> 
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Oct 26, 2006 1:12 pm
by feyd
bufhal, please don't try to separate a single block of code into multiple highlighting blocks (especially if you're skipping segments).

ok, sorry about that

Posted: Thu Oct 26, 2006 1:48 pm
by bufhal
ok, sorry about that

Posted: Thu Oct 26, 2006 1:58 pm
by John Cartwright

Code: Select all

$emails = array('et@email.com', 'dd@email.com' , 'rpec@email.com' , 'mkt@email.com');

if (!empty($_GET['email_to']) && in_array($_GET['email_to'], $emails)) {

   if (mail(  )) {
      echo 'Email sent';
      exit();
   }
}
Three things here

1. When assigning values to an array without keys, there is no need to automatically assign them. PHP will do that for you.
2. Since you want to append the email to a picture that you will click, wrap a link with ?email_to=email@goes.here around the appropriate image. This variable will be accessible through $_GET['email_to'] as shown in the code above
3. Make sure you will out the mail() function parameters. I just left it blank.

thank you

Posted: Thu Oct 26, 2006 2:10 pm
by bufhal
Thank you very much, Jcart.

not sure what you mean here.
3. Make sure you will out the mail() function parameters. I just left it blank


So if I wrap my email gifs with

Code: Select all

?email_to=email@goes.here
And use your posted code with my form, this should work?

Thank you

php email image to populate email address on form

Posted: Fri Oct 27, 2006 9:00 am
by bufhal
Hi;
Still attempting to wrap some PHP around "images of the
email recipient's address" that, when clicked will
go to a form page. The form page has a subject and a
messagebox. When a visitor fills in those two boxes
and submits, the information will go to the email
address. I am stuck. Please foffer some assistance.
I appreciate any help.


Form Page:

Code: Select all

<?php
$emails = array('gz@email, 'dd@email.com' , 
'rpec@email.com' , 'mkt@email.com'); 

if (!empty($_GET['email_to']) && 

in_array($_GET['email_to'], $emails)) { 

   if (mail(  )) { 
      echo 'Email sent'; 
      exit(); 
   } 
}
?> 

<center> 
<body> 
 
<h2>Please email us...</h2> 


<form action="mail2.php" method="POST"> 
<p><b>Subject</b><br> 
<input type="text" name="subject" size=50> 
<br><br> 
<b>Message</b><br> 
<textarea cols=40 rows=10 

name="message"></textarea><br><br>
<input type="submit" value=" Send "> 
</form>
</body></center> 
</html>
Email link with image:
<map name="Map">
<area shape="rect" coords="0,-2,153,14"
href="mail4.html">
</map>
<a href="?email_to=" img src="images/Ed_email.gif"
width="152" height="14" border="0" usemap="#Map">

Posted: Fri Oct 27, 2006 9:05 am
by Chris Corbyn
Anything look funny with our syntax highlightng to you? ;)

Posted: Fri Oct 27, 2006 12:14 pm
by bufhal
yeah it looks red...........................