Forum Moderators: coopster
Again - same client as my last post. Windows Server, running PHP5 - my scripts were functioning fine in tests on two different servers (of course, they were Unix and running PHP4!), and when I uploaded everything failed and I have rewrite everything.
So, here's the issue on *this* one.
I'm using PHPMailer. I'm also using the tutorial that was posted on phpfreaks.com, and using the congif.php and the MailClass.php files, as well (these are only to set the redundant classes so you don't have to type them over and over for every page).
The section that was working before was this:
$emailto = '';
switch ($mailto) {
case "":
$mailtoerror = "1";
$send = "no";
break;
case "sales":
$emailto = "email1@test.com";
break;
case "partners":
$emailto = "email2@test.com";
break;
case "support":
$emailto = "email3@test.com";
break;
case "other":
$emailto = "email4@test.com";
break;
}
(By the way, I *cannot* have a default set - the client has already made this clear.)
Now, for some reason, I can't make the PHPMailer script recognize that the end user is selecting an e-mail address to send the form to. So it goes nowhere. I've tried using AddAddress, Receipient, ToEmail - all kinds of things, and nothing's working. It acts like it's sending - but nothing comes through at all.
Here's what I have so far:
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
$mail = new FreakMailer();
$mail->From = "$name";
$mail->FromName = "$email";
$mail->ToEmail = "$mailto";
$body = "Name: $name<br>";
$body.= "Phone: $phone<br>";
$body.= "e-Mail address: $email<br>";
$body.= "$comments";
$comments = stripSlashes($comments);
$mail->ContentType = "text/html";
$mail->Subject = "A message from the Contact Form";
$mail->Body = $body;
$mail->Send();
So, again - you all are lifesavers. If I could get some help making the script "see" which selection the end user has chosen and stick it in the "To" field, I'd appreciate it :)
Actually, that *was* an issue, about 3 days ago. The administrator/tech support decided that the benefits outweighed the risks, and turned them "on", which helped a lot of issues. (This won't be used for *anything* but these forms - and I've made sure these scripts are very secure - so they were okay with turning them on).
How are you grabbing $mailto and the rest? Maybe you need to switch to $_GET["mailto"] or similar ...? <<
I could try the $_GET["mailto"] - but I don't know where to put that. (someone else suggested using $_HTTP_POST VARS[$var_name] - but I didn;t know wher to put that, either.
As for how I'm grabbing them...well, you've already seen the switch function in my PHP file. I'll show you the code in the HTML file...(the HTML file is called in as an include to the PHP file):
<b <? if ($mailtoerror!= "")?> >What is the nature of your inquiry?</b>
<select class="form" name="mailto">
<option value=""></option>
<option value="sales" name="sales">Sales</option>
<option value="partners" name="partners">Partners</option>
<option value="support" name="support">Customer Support</option>
<option value="other" name="other">Other</option>
</select>
That's really all there is to it.
Oh yeah, and my form's action is set to $PHP_SELF.
If you need any other info, let me know.
And you've saved my ass once today, I swear I'll send you chocolates if you save it again!
$mail->From = "$name"; $mail->FromName = "$email"; $mail->ToEmail = "$mailto"; Try
$mail->From = $name; $mail->FromName = $email; $mail->ToEmail = $mailto; BTW, use
$_GET["mailto"] to define $mailto pre-processing ... $mailto = $_GET["mailto"]; You could also use:
switch ($_GET["mailto"]) { It's accessing the GET array passed as a result of the form submission. (Much safer to use
method=post instead of the method=get default. The form elements are not carried in the URL string, using post.) $HTTP_POST_VARS[] and $HTTP_GET_VARS[] are deprecated in favor of $_POST[] and $_GET[]. (You would have needed to use $HTTP_GET_VARS[] with your form, anyway.)
I think you're right on that - it's just a matter of getting the mailer function to recognize which option is selected.
I tried the "switch" edit you suggested, and it seemed to be a little *too* strict. When I test out the form, even when I select an option, it gives me a warning that is didn't do so (it's a required field to pick one - so the warning is that I didn't select something from a required field).
When I first wrote this script, I had that same problem, but I can't remember what I did to fix it. But it *has* to remain a required field.
Anyway, I also tried the alternate - the $mailto=$_GET thing - but it acts weird, too. It's enough to make it pass the "required field" thing and move on to my thank you page, but nothing comes through the system to my inbox.
Maybe I'm putting it in the wrong place? I've tried several different areas, but no go.
Oh, and the ToEmail thing makes my page come up as a blank white page - so that's gotta go. I've now reverted back to the AddAddress()
I'm going to keep plugging away at it - but if you have any further suggesteions, that'd be awesome!