SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 25
-
May 8, 2005, 12:04 #1
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Need php contact script that can go to 2 addresses
Hello-- I'm not a programmer. The client I have is free so I have no money to pay, but have lots of appreciation to give! My problem is I have a PHP script that works great, however, there are several choices in the "Attention" field. The customer wants some of the choices, like Sales and Billing to go to one email address and the others, like Tech Support and Other to go to another email address, both from his domain.Can anyone help me accomplish this without creating more than one input document?
-
May 8, 2005, 14:27 #2
- Join Date
- Feb 2004
- Location
- Örebro, Sweden
- Posts
- 2,716
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
One solution would be to store the different emails in an array, and then use the selected value to determine which email that the message should be sent to. First, let's start with the user interface - the list of choices:
HTML Code:<select name="attention"> <option value="sales">Sales</option> <option value="billings">Billings</option> </select>
PHP Code:$emails = array(
'sales' => 'sales@a-domain.com',
'billings' => 'billings@another-domain.com'
);
PHP Code:if( isset($_POST['attention']) )
{
$attention = strtolower($_POST['attention']);
$email = isset($emails[$attention]) ? $emails[$attention] : false;
if( $email === false ) // the specified attention is invalid
die('the selected attention is not valid...');
// send the email here...
}
ERIK RIKLUND :: Yes, I've been gone quite a while.
-
May 8, 2005, 18:37 #3
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you so much for your reply!! I pasted the php string, and got a result, but not the expected result. I'm sending myself email now. I'm not sure what to do with the second string, even though I'm sure it holds the key to the solution.
-
May 9, 2005, 00:33 #4
- Join Date
- Feb 2004
- Location
- Örebro, Sweden
- Posts
- 2,716
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Is it the array that's confusing you? Just place it at the top of your script.ERIK RIKLUND :: Yes, I've been gone quite a while.
-
May 9, 2005, 06:23 #5
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I put it on the second line. The email goes to hi@... no matter which field in the contact form is selected. Again, thanks and remember I'm a programming dummie of the most extreme kind. Forgive my ignorance.
<?php
$myemail = "hi@hungryscafe.com";
$emails = array(
'Webmaster' => 'webmaster@hungryscafe.com',
'Other' => 'sue@hungryscafe.com'
);
$ccx = "";
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2></h2>\n";
}
echo $badinput;
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn . "(" . $ccopy . ")" ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $visitormail\r\n";
if (($ccopy == "") && ($visitormail != ""))
mail($visitormail, $subject, $message, $from);
if ($myemail != "")
mail($myemail, $subject, $message, $from);
if ($ccx != "")
mail($ccx, $subject, $message, $from);
?>
<p align="center"> <?php echo $todayis ?></p>
<p align="center"><br />
<strong>Thank you, <span class="style77"><?php echo $visitormail ?> </span>for contacting our office. </strong><br />
<br />
<strong>Attention/strong> <?php echo $attn ?></p>
<p align="center"><br />
<strong>Message/strong><br />
<span class="style77">
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php
-
May 9, 2005, 06:39 #6
- Join Date
- Feb 2004
- Location
- Örebro, Sweden
- Posts
- 2,716
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Change the following two lines:
PHP Code:if ($myemail != "")
mail($myemail, $subject, $message, $from);
PHP Code:mail($email, $subject, $message, $from);
ERIK RIKLUND :: Yes, I've been gone quite a while.
-
May 9, 2005, 07:44 #7
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The change made the email go to the sender.
-
May 9, 2005, 09:03 #8
- Join Date
- Feb 2004
- Location
- Örebro, Sweden
- Posts
- 2,716
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
You haven't added the code where the selected attention is used to determine which email the message should be sent to. I didn't see that before, and just assumed that the email was stored in $email.ERIK RIKLUND :: Yes, I've been gone quite a while.
-
May 9, 2005, 09:47 #9
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If I am understanding correctly, there is simply a drop-down field on the form needed that will determine where the mail is sent? Is this correct?
If so, all you need to do is put the posted attention field as the eMail address to be mailed to:PHP Code:$mail_to = $_POST['attn_field'];
-
May 9, 2005, 14:07 #10
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think it's time to go to school. What do you suggest I take first?
-
May 9, 2005, 14:12 #11
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you are wanting to learn PHP there's no need for 'school' per se. Go out and get a copy of PHP Bible. It's in a very easy format and helped me a lot when first learning the language. However, I'd be more than happy to help you get your current problem working though.
-
May 9, 2005, 14:27 #12
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This seems like the easiest thing to do, but I am ill equipped, as you can see from the first person who tried to help. If this were a paying job I'd go out and get a real programmer like one of you! Go to http://hungryscafe.com/contact.php to see my problem in full. The "customer" has asked me to send:
Technical Support and General Support to hi@hungryscafe.com
and
Sales and Webmaster to webmaster@hungryscafe.com.
You are all so kind to help--I'm so new to this. I've only been putting pages together for about 6 months. My strength is obviously not on the programming side!
-
May 9, 2005, 14:33 #13
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
SHould I get the regular PHP bible published in 2002 or mysql with PHP5? I guess the latter being more recent...
-
May 9, 2005, 19:21 #14
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The latter would be the best probably but it would be a wise idea to learn PHP 4.x as well because most servers are not upgraded to PHP 5 as of yet.
-
May 9, 2005, 19:25 #15
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Very easy to do what you need...
The easiest way is to put the eMail address as the value of the option field but then you run the risk of spam crawlers scraping it from the code.
The best way to do it is check for the value and set the eMail accordingly. The default in the switch is the value that will be set if no option is selected. You will also need to get rid of the whitespace before the first and last characters of the values in your options for the below code to function. The case represents the value pased from that option.PHP Code:$mail_to = $_POST['attn'];
switch($mail_to) {
case 'Technical Support':
$mail_to = 'techsupport@domain.com';
break;
case 'General Support':
$mail_to = 'general@domain.com';
break;
case 'Webmaster':
$mail_to = 'webmaster@domain.com';
break;
case 'Sales':
$mail_to = 'sales@domain.com';
break;
default:
$mail_to = 'info@domain.com';
break;
}
-
May 9, 2005, 19:28 #16
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
very nice design by the way!
-
May 10, 2005, 08:27 #17
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nice of you to comment on my design, especially coming from a designer. THe client liked it but I didn't believe them. It has its redeeming qualities...
I tried the code. There is a change-- now I get two identical emails, but both sent to hi@... So if I select Webmaster, I get 2 emails sent to hi@... What have I done wrong? I'm ordering the bible today.
-
May 10, 2005, 10:02 #18
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can you post the code as it is now so I can get a better look?
As far as the design... it has a very clean modern look to it which I love. The only thing I would suggest is maybe adding something to the homepage to set it apart from the rest of the site. Nothing dramatic, but you could keep the same 'square' image theme that you've got going at the top and create a shape built out of say 5 or 7 squares. Below is something I threw together to give you an idea of what I mean (keep in mind I did this in about 10 minutes so it's not perfect)
-
May 10, 2005, 10:36 #19
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That is wonderful!!! I will do something about it. You are so right.
-
May 10, 2005, 10:39 #20
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sorry I didn't see the first part. I liked your idea so much that I forgot what we were originally doing here. lol
<?php
$myemail = "hi@hungryscafe.com";
$ccx = "";
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
$mail_to = $_POST['attn'];
switch($mail_to) {
case 'Technical Support':
$mail_to = 'hi@hungryscafe.com';
break;
case 'General Support':
$mail_to = 'hi@hungryscafe.com';
break;
case 'Webmaster':
$mail_to = 'webmaster@hungryscafe.com';
break;
case 'Sales':
$mail_to = 'jcs@hungryscafe.com';
break;
default:
$mail_to = 'hi@hungryscafe.com';
break;
}
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2></h2>\n";
}
echo $badinput;
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn . "(" . $ccopy . ")" ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $visitormail\r\n";
if (($ccopy == "") && ($visitormail != ""))
mail($visitormail, $subject, $message, $from);
if ($myemail != "")
mail($myemail, $subject, $message, $from);
if ($ccx != "")
mail($ccx, $subject, $message, $from);
?>
<p align="center"> <?php echo $todayis ?></p>
<p align="center"><br />
<strong>Thank you, <span class="style77"><?php echo $visitormail ?> </span>for contacting our office. </strong><br />
<br />
<strong>Attention/strong> <?php echo $attn ?></p>
<p align="center"><br />
<strong>Message/strong><br />
<span class="style77">
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>
-
May 10, 2005, 11:51 #21
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Okay, going through all of that was a bit 'jumbled' so I wrote a controller for you. I've pasted it below but I'm sure the spacing will be thrown off. If you want the actual file just send me an eMail I'll send it to you. You can just click my username and a drop-down list will come with a link to eMail me.
You will need to add a textfield to your contact form so the visitor can type in their name. The field name should be 'visitor'.
PHP Code:<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$ccopy = $_POST['ccopy'];
$attn = $_POST['attn'];
$notes = stripcslashes($_POST['notes']);
if(!$visitormail || !$notes || !$visitor) {
//if visitor, visitormail or notes fields were left blank
echo "<h1>Use Back: Please enter all information</h1> \n";
}
else {
//Decide where eMail should go
switch($attn) {
case 'Technical Support':
$mail_to = 'hi@hungryscafe.com';
break;
case 'General Support':
$mail_to = 'hi@hungryscafe.com';
break;
case 'Webmaster':
$mail_to = 'webmaster@hungryscafe.com';
break;
case 'Sales':
$mail_to = 'jcs@hungryscafe.com';
break;
default:
$mail_to = 'hi@hungryscafe.com';
break;
}
//Today's date
$todayis = date("l, F j, Y, g:i a") ;
//eMail Subject
$subject = $attn;
//eMail Message
$message = "
$todayis [EST]
Attention: $attn
Message: $notes
From: $visitor ($visitormail)
Additional Info:
IP: $ip
Browser: $httpagent
Referral: $httpref";
//eMail From
$from = "From: $visitor <$visitoremail>";
//Mail Form
if($ccopy) {
//If CCopy was selected add visitor email
$mail_to = "$mail_to, $visitormail";
$send_form = mail($mail_to, $subject, $message, $from);
}
else {
//ccopy was not selected
$send_form = mail($mail_to, $subject, $message, $from);
}
//If form was sent echo thank you message
if($send_form) {
?>
<p align="center"> <?php echo $todayis ?></p>
<p align="center"><br />
<strong>Thank you, <span class="style77"><?php echo $visitor ?> </span>for contacting our office. </strong><br />
<br />
<strong>Attention:</strong> <?php echo $attn ?></p>
<p align="center"><br />
<strong>Message:</strong><br />
<span class="style77">
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>
<?php
}
else {
echo "<p>We are sorry but there was a problem sending your information. Please try again.</p>";
}
}
?>
-
May 11, 2005, 05:14 #22
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I tried this script. No matter what fields were filled in (all) in the contact form, I got an error message: Use Back: Please enter all information.
I don't want you to do any more I feel quilty. I'm going to get the bible. I will let you know when I figure this out. I'm sure you have given me perfectly wonderful stuff to work with that may even need just one minor tweak, but I'm clueless. I will let you know when I have a clue.
Oh, I moved the images around: http://www.hungryscafe.com/Copy%20of%20index.html
Thank you !! And have a great day!! Especially on the beach. I grew up on one too it's the best way!
-
May 11, 2005, 05:41 #23
- Join Date
- May 2005
- Location
- Houston, Texas, USA
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
750am CST. Okay, I changed a couple things (like the error message part) and I got it to work. It's not working exactly like I had intended, BUT IT'S WORKING!!! I'm gettin the bible... Thank you so much!!!!!
-
May 11, 2005, 06:28 #24
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Your are more than welcome!
The reason it wouldn't work with the script I did is because you didn't add a visitor text field to the contact form. You want to be able to display their name in your message but have given no way for that info to be added.
If you add the following to your Contact Form the script I pasted will work without a hitchCode:Name: <input type='text' name='visitor' id='visitor'>
PHP Code:if(!$visitormail || !$notes || !$visitor) {
PHP Code:if(!$visitormail || !$notes) {
-
May 22, 2005, 19:03 #25
- Join Date
- May 2005
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Follow-up on contact script
Hello KDESIGNS!
I can do a little PERL and in searching for a contact script I found this thread. This is pretty much the approach I wanted to develop. While I've looked at php a time or two, and tested my host's installation, etc. -- thing is, whereas in PERL the script is in a protected directory, I don't see how this php script is protected, that is, how the "embedded" eMail addresses are kept from public access.
If you find it not too inconvenient, wouldst thou post a hint or two on this?
thx
mike
Bookmarks