Jump to content

Help with mail form...


ArrudaC

Recommended Posts

Hi all.

 

I have the following code;

<?php
$to = $_REQUEST['bustype'];
$from = $_REQUEST['email'];
$title = $_REQUEST['title'];
$fname = $_REQUEST['firnam'];
$lname = $_REQUEST['lasnam'];
$message = $_REQUEST["frmmsg"];

$headers = "From: $from";
$subject = "Web Contact Data.";

$date = date("j F Y");
$time = date("g:i A");

$fields = array ();
$fields{"firnam"} = "First Name";
$fields{"lasnam"} = "Last Name";
$fields{"email"} = "E-Mail";
$fields{"possition"} = "Possition";
$fields{"bustype"} = "Business Type";
$fields{"foundus"} = "Found us on";
$fields{"frmmsg"} = "Customer's message";

$headers2 = "From: noreply@test.com";
$subject2 = "$fname, we have received your query.";
$autoreply = "Dear $title $lname, $firnam,

and...

<select name="bustype" class="dropforopt">
<option value="" disabled="disabled" selected="selected">Type of business...</option>
<option value="Guest House""noreply@test.com">Guest House</option>
<option value="noreply@test.com""2">Village Haul</option>
<option value="noreply@test.com""3">Small Office (up to 10 people)</option>
<option value="noreply@test.com""4">Medium Office (up to 50 people)</option>
<option value="noreply@test.com""5">Hair Salon</option>
</select>

I have already had a play at changing the code as seen in the red line above but now the form will send the data to the e-mail of who's requesting information but won't send it to who should provide the information.

 

It will work if I choose Village Haul and so on but not if I pick the first option.

 

Still, even when it worked, I wasn't receiving the type of business chosen. Instead I was receiving the e-mail that is attached to that option.

 

How do I get over this issue please?

 

What am I doing wrong?

 

I am not a coder so my experience resumes to having some code and changing it as I need.

 

Many thanks in advance.

 

Regards,

Albert

 

Link to comment
Share on other sites

The problem is that you are using double quotes inside of a double quoted attribute value. In the following <option> tag, "Guest House" is the only thing that gets passed. And "noreply@test.com" is ignored by the browser.

<option value="Guest House""noreply@test.com">Guest House</option>

The reason why the following works, is because the email address is before the first closing double quote. And "2" is ignored by the browser.

<option value="noreply@test.com""2">Village Haul</option>

 

Link to comment
Share on other sites

So that I can get the correct data from the customer and new what type of business is, how do I separet the e-mail from it?

 

I mean, I can use just one single e-mail where all queries are submited.

 

I just used this form and twiked it as this form I have used it in the past on another project but never even realized this.

 

Much appreciated for your input.

Link to comment
Share on other sites

Side note: it's best to avoid using $_REQUEST. The variable is generated based on whatever is sent using GET, POST, COOKIES, etc. and is more susceptible to attacks. More information about $_REQUEST can be found here:

http://php.net/manual/en/reserved.variables.request.php

 

It better to using the variable which corresponds to how the information is being passed to PHP. If your form's method is set to POST, for example, you would be better off to us $_POST. More information can be found here:

http://php.net/manual/en/reserved.variables.post.php

Link to comment
Share on other sites

You could just pass the business type. And then have PHP look up the corresponding email address(es).

 

Many thanks.

 

If I only knew how to make that happened.

 

But still, I get what you are saying.

 

I'll do some digging and see what I can find about it.

 

Many thanks.

Link to comment
Share on other sites

Basically, you would change your <option> tags to something like this

<select name="bustype" class="dropforopt">
<option value="" disabled="disabled" selected="selected">Type of business...</option>
<option value="Guest House">Guest House</option>
<option value="Village Haul">Village Haul</option>
<option value="Small Office">Small Office (up to 10 people)</option>
<option value="Medium Office">Medium Office (up to 50 people)</option>
<option value="Hair Salon">Hair Salon</option>
</select>
 
Then on the PHP side, you could run a test on the "bustype" variable using something like this
<?php
switch($_REQUEST['bustype']) {
    case 'Guest House':
        $to = 'guest.house@test.com';
        break;
 
    case 'Village Haul':
        $to = 'village.haul@test.com';
        break;
 
    case 'Small Office':
        $to = 'sm.office@test.com';
        break;
 
    case 'Medium Office':
        $to = 'med.office@test.com';
        break;
 
    case 'Hair Salon':
        $to = 'hair.salon@test.com';
        break;
 
}
?>
Link to comment
Share on other sites

I was sure on how to change the HTML side of it but utterly clueless as to how to change the php to work.

 

As I have said, sadly I am not a coder. At best, I take code (ops sorry) and change it or try to change it to what I need.

 

Many thanks to all especially to cyberRobot.

 

On another note, I have been dabling on this reply to include the title and lastname but I got, on my first attempt an violation php error of sort.

 <p><br />
            Hello <?php print stripslashes($_REQUEST['firnam']); ?>. 
  <br />
  <br />
            Your message was successfully sent to us. </p>

my attempt bellow did not work...

 <p><br />
            Hello <?php print stripslashes($_REQUEST['tytle']['firnam']['lasnam']); ?>. 
  <br />
  <br />
            Your message was successfully sent to us. </p>

Many thanks to all.

 

Albert

Link to comment
Share on other sites

I have changed my code to include the php bit sugested above but now customer side is not receiving a copy of the form.

<?php

switch($_REQUEST['bustype']) {
    case 'Guest House':
        $to = 'guesthouse@test.com';
        break;
 
    case 'Village Haul':
        $to = 'vhaul@test.com';
        break;
 
    case 'Small Office':
        $to = 'soffice@test.com';
        break;
 
    case 'Medium Office':
        $to = 'moffice@test.com';
        break;
 
    case 'Hair Salon':
        $to = 'Hsalon@test.com';
        break;
}

$from = $_REQUEST['email'];
$title = $_REQUEST['title'];
$fname = $_REQUEST['firnam'];
$lname = $_REQUEST['lasnam'];
$message = $_REQUEST["frmmsg"];

$headers = "From: $from";
$subject = "Web Contact Data.";

$date = date("j F Y");
$time = date("g:i A");

$fields = array ();
$fields{"firnam"} = "First Name";
$fields{"lasnam"} = "Last Name";
$fields{"email"} = "E-Mail";
$fields{"possition"} = "Possition";
$fields{"bustype"} = "Business Type";
$fields{"foundus"} = "Found us on";
$fields{"frmmsg"} = "Customer's message";

$headers2 = "From: noreply@test.com";
$subject2 = "$fname, we have received your query.";
$autoreply = "Dear $title $lname, $firnam,

I have removed the following from my existing code to add the new code;

$to = $_REQUEST['bustype'];

Was I wrong in doing so? Is this the culpride?

 

Many thanks.

 

Albert

Link to comment
Share on other sites

You need to use the full variable name. Try changing this

Hello <?php print stripslashes($_REQUEST['tytle']['firnam']['lasnam']); ?>.
 
To this
Hello <?php print stripslashes($_REQUEST['tytle'] . $_REQUEST['firnam'] . $_REQUEST['lasnam']); ?>.
 
Also, I imagine that $_REQUEST['tytle'] should be $_REQUEST['title'].
Link to comment
Share on other sites

 

You need to use the full variable name. Try changing this

Hello <?php print stripslashes($_REQUEST['tytle']['firnam']['lasnam']); ?>.
 
To this
Hello <?php print stripslashes($_REQUEST['tytle'] . $_REQUEST['firnam'] . $_REQUEST['lasnam']); ?>.
 
Also, I imagine that $_REQUEST['tytle'] should be $_REQUEST['title'].

 

LOL... apologies, my spelling can be at times atrocious.

 

One thing though their all joint together with no spaces.

 

Many thanks. 

Link to comment
Share on other sites

Hi.

 

After adding the extra php code to select the e-mail the form now does not send an acknowledgement to the user.

 

My code is below.

<?php

switch($_REQUEST['bustype']) {
    case 'Guest House':
        $to = 'gh@test.com';
        break;
 
    case 'Village Haul':
        $to = 'vh@test.com';
        break;
 
    case 'Small Office':
        $to = 'so@test.com';
        break;
 
    case 'Medium Office':
        $to = 'mo@test.com';
        break;
 
    case 'Hair Salon':
        $to = 'hs@test.com';
        break;
}

$from = $_REQUEST['email'];
$title = $_REQUEST['title'];
$fname = $_REQUEST['firnam'];
$lname = $_REQUEST['lasnam'];
$message = $_REQUEST["frmmsg"];

$headers = "From: $from";
$subject = "Web Contact Data.";

$date = date("j F Y");
$time = date("g:i A");

$fields = array ();
$fields{"firnam"} = "First Name";
$fields{"lasnam"} = "Last Name";
$fields{"email"} = "E-Mail";
$fields{"possition"} = "Possition";
$fields{"bustype"} = "Business Type";
$fields{"foundus"} = "Found us on";
$fields{"frmmsg"} = "Customer's message";

$headers2 = "From: noreply@test.com";
$subject2 = "$fname, we have received your query.";
$autoreply = "Dear $title $lname, $firnam,

Thank you for contacting us. 

We will get back to you as soon as possible, usually within 6 hours. 

If you have any more questions, please consult our website at www.flamewatch.co.uk.

Here is a copy of your message:
-------------------------------------------------------------------------------
$message
-------------------------------------------------------------------------------

Have you got this e-mail by mistake? If so, please do let us know by e-mailing us at general@test.com.

Do you need a new computer? A computer part or upgrade? Please contact us on 0845 123 4567 for more information or a quotation.

This is an unmonitored mail box. Please do not reply to this e-mail.

kind regards, 
Customer Care Dep.
Date: $date
Time: $time";

$body ="We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a],$date);}
$body .= $date;
$body .= $time;


$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);

?>

What have I done wrong with the added code?

 

I am sure I have not implemented it as I should have done...

 

Many thanks.

 

Regards,

Albert

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.