/    Sign up×
Community /Pin to ProfileBookmark

Need help with contact form

I want to create combo box with 3 different emails. When the visitor chooses the option, the email would be sent to that particular email.
Let’s say we have different branches:

  • 1. sales [email][email protected][/email]
    2.information [email][email protected][/email]

  • 3. careers [email][email protected][/email]
  • If a visitor chooses sales, the messege would be sent to [email][email protected][/email]
    I have a script that sends messege to one e-mail, i am trying to modify it, but i just don’t know from where to start.
    Please help me.
    I appreciate any help.

    Tigerasya

    to post a comment
    PHP

    11 Comments(s)

    Copy linkTweet thisAlerts:
    @JonaFeb 26.2005 — [font=trebuchet ms]Well, the form would have this in it...[/font]

    <i>
    </i>&lt;label&gt;Select department to contact:
    &lt;select size="1" name="mailAddr"&gt;
    &lt;option name="[email protected]"&gt;Sales&lt;/option&gt;
    &lt;option name="[email protected]"&gt;Information&lt;/option&gt;
    &lt;option name="[email protected]"&gt;Careers&lt;/option&gt;
    &lt;/select&gt;
    &lt;/label&gt;


    [font=trebuchet ms]Then the PHP page would retrieve it like so:[/font]

    [code=php]
    $to = $_POST["mailAddr"];
    [/code]


    [font=trebuchet ms]How do you have your mailer set up? (The variables and the mail function, I don't need anything else really).[/font]
    Copy linkTweet thisAlerts:
    @phpnoviceFeb 26.2005 — The above contains three errors. The OPTION tags should be using the [b]value[/b] attribute -- not the [b]name[/b] attribute. Otherwise...
    [i]Originally posted by tigerasya [/i]

    [B]I want to create combo box with 3 different emails. When the visitor chooses the option, the email would be sent to that particular email.[/B][/QUOTE]

    If you're using a mailer you've written yourself, then the above corrected answer is probably sufficient for your needs. However, if you're using a pre-written mailer (such as FormMail), then you'll want the name of your SELECT to be the name required by the mailer for the recipient's email address:
    <i>
    </i>&lt;select name="recipient" size="1"&gt;
    &lt;option value="[email protected]"&gt;Sales&lt;/option&gt;
    &lt;option value="[email protected]"&gt;Information&lt;/option&gt;
    &lt;option value="[email protected]"&gt;Careers&lt;/option&gt;
    &lt;/select&gt;
    Copy linkTweet thisAlerts:
    @JonaFeb 26.2005 — [font=trebuchet ms]Haha, nice catch! Those late nights can really get to you sometimes, you know...[/font]
    Copy linkTweet thisAlerts:
    @tigerasyaauthorFeb 26.2005 — Thank you guys. The form i did myself, that's not the hard part. The hard part is to adjust the php code.

    here is the php code:

    <?php

    $admin_name="my name";

    $admin_email="[email protected]";

    if(empty($req)) {

    $req='';

    }

    /* Which request did we read in? */

    switch ($req) {

    /* User submitted form
    send the message */
    case SendMsg:
    /* read in info from the form */
    $name = $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $homepage = $_REQUEST['homepage'];
    $message = $_REQUEST['message'];


    if (empty($name) || empty($email) || empty($message)) {

    ErrMsg();

    }

    /* compile the message */

    $msg = "Name: ".$name."nEmail: ".

    $email."nHomepage: ".$homepage."nMessage:nn".$message;

    /* mail it and redirect */
    mail($admin_email, "Feedback From "$name [$email]"", $msg, "From: $email");
    header("Location: http://www.website.com/feedback.php?req=MsgSent");
    break;

    /* Print we have
    sent the message */
    case MsgSent:
    MessageSent();
    break;

    /* No information in $req
    print out the form */
    default:
    ErrMsg();

    }

    /* Print the error message */

    function ErrMsg() {

    include("error.html");

    }

    /* Print that the message was sent */

    function MessageSent() {

    include("thankyou.html");

    }

    ?>

    Thanks beforehand.

    Tigerasya
    Copy linkTweet thisAlerts:
    @JonaFeb 26.2005 — [font=trebuchet ms]Change the following[/font]

    [code=php]
    $admin_email="[email protected]";
    [/code]


    [font=trebuchet ms]into this:[/font]

    [code=php]
    $admin_email = (isset($_REQUEST["nameOfSelectBox"])||!empty($_REQUEST["nameOfSelectBox"]))?$_REQUEST["nameOfSelectBox"]:"[email protected]";
    [/code]


    [font=trebuchet ms]Of course, you'll need to replace both instances of "nameOfSelectBox" with the name you give your SELECT form element, and "[email protected]" will have to be replaced with the default address that email should be sent to (in the event that nothing was selected).[/font]
    Copy linkTweet thisAlerts:
    @bokehFeb 26.2005 — If you don't want to give out your email to the world you could do it like this, (I think!).

    <label>Select department to contact:

    <select size="1" name="mailAddr">

    <option value="sales">Sales</option>

    <option value="info">Information</option>

    <option value="careers">Careers</option>

    </select>

    </label>

    [code=php]
    $admin_email = $_POST["mailAddr"];
    $admin_email = $admin_email . '@a.com';
    [/code]
    Copy linkTweet thisAlerts:
    @tigerasyaauthorFeb 27.2005 — this is what php code looks like right now:

    <?php

    $admin_name="my name";

    $admin_email = (isset($_REQUEST["recipient"])||!empty($_REQUEST["recipient"]))?$_REQUEST["recipient"]:"[email protected]";

    if(empty($req)) {

    $req='';

    }


    /* Which request did we read in? */

    switch ($req) {

    /* User submitted form
    send the message */
    case SendMsg:
    /* read in info from the form */
    $name = $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $recipient = $_REQUEST['recipient'];
    $homepage = $_REQUEST['homepage'];
    $message = $_REQUEST['message'];


    if (empty($name) || empty($email) || empty($message)) {

    ErrMsg();

    }

    /* compile the message */

    $msg = "Name: ".$name."nEmail: ".

    $email."nHomepage: ".$homepage."nMessage:nn".$message;

    /* mail it and redirect */
    mail($admin_email, "Feedback From "$name [$email]"", $msg, "From: $email");
    header("Location: http://www.website.com/feedback.php?req=MsgSent");
    break;

    /* Print we have
    sent the message */
    case MsgSent:
    MessageSent();
    break;

    /* No information in $req
    print out the form */
    default:
    ErrMsg();

    }

    /* Print the error message */

    function ErrMsg() {

    include("error.html");

    }

    /* Print that the message was sent */

    function MessageSent() {

    include("thankyou.html");

    }

    ?>

    Now...everything works, but to some reason, although i check that the information required to be filled in, the script, goes to error page, but it still sends the empty messege to the default recipient.

    Another problem is that to some reason the middle recipient, does not receive the email.

    Could you please advice me anything here?

    Thanks...You all did a pretty good job here. I appreciate it.

    Tigerasya
    Copy linkTweet thisAlerts:
    @JonaFeb 27.2005 — [font=trebuchet ms]Try this.[/font]

    [code=php]
    <?php
    $admin_name="my name";
    $admin_email = (isset($_REQUEST["recipient"])&&!empty($_REQUEST["recipient"]))?$_REQUEST["recipient"]:"[email protected]";

    if(empty($req)) {
    $req='';
    }

    switch ($req) {
    case "SendMsg":

    $name = $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $homepage = $_REQUEST['homepage'];
    $message = $_REQUEST['message'];

    if (empty($name) || empty($email) || empty($message)) {
    ErrMsg();
    }

    $msg = "Name: ".$name."nEmail: ".
    $email."nHomepage: ".$homepage."nMessage:nn".$message;

    mail($admin_email, "Feedback From "$name [$email]"", $msg, "From: $email");
    header("Location: http://www.website.com/feedback.php?req=MsgSent");
    break;

    case "MsgSent":
    MessageSent();
    break;

    default:
    ErrMsg();
    }

    function ErrMsg() {
    include("error.html");
    }

    function MessageSent() {
    include("thankyou.html");
    }
    ?>
    [/code]
    Copy linkTweet thisAlerts:
    @smercerFeb 27.2005 — I have a working contact us page at www.macleaybec.com.au and the code for this is:

    contact_us.htm:
    [code=php]
    <html>
    <head>
    <title>Contact us</title>

    <link rel="stylesheet" href="Stylesheet.css" type="text/css">
    </head>

    <body>

    <form method="post" action="correspondence_confirm.php">
    <table>
    <tr>
    <td>First Name:
    </td>
    <td><input name="fname">
    </td>
    </tr>

    <tr>
    <td>Surname:
    </td>
    <td><input name="surname">
    </td>
    </tr>

    <tr>
    <td>Phone:
    </td>
    <td><input name="phone">
    </td>
    </tr>

    <tr>
    <td>Fax:
    </td>
    <td><input name="fax">
    </td>
    </tr>

    <tr>
    <td>Email:
    </td>
    <td><input name="email" size="66">
    </td>
    </tr>

    <tr>
    <td>Company Name:
    </td>
    <td><input name="busname">
    </td>
    </tr>

    <tr>
    <td>Subject:
    </td>
    <td><input name="subject">
    </td>
    </tr>

    <tr>
    <td>Attention:
    </td>
    <td><input type="radio" name="attention" value="Manager">Manager<br/>
    <input type="radio" name="attention" value="Aboriginal Enterprise Development Officer">Aboriginal Enterprise Development Officer<br />
    </td>
    </tr>

    </table>
    <p>Message:</p>
    <textarea name="message" cols="64" rows="20"></textarea><br />
    <input type="reset" value="Reset">
    <input type="submit" value="Send">

    </form>
    </body>
    </html>[/code]


    correspondence_confirm.php:
    [code=php]<html>
    <head>
    <title>
    Please confirm the information is correct
    </title>

    </head>

    <body>

    <h1>Please confirm this message</h1>
    <p><?php

    echo "<b>First Name:</b> $fname <br />";
    echo "<b>Surname:</b> $surname<br />";
    echo "<b>Phone:</b> $phone<br />";
    echo "<b>Fax:</b> $fax<br />";
    echo "<b>Email:</b> $email<br />";
    echo "<b>Company Name:</b> $busname<br />";
    echo "<b>Subject:</b> $subject<br />";
    echo "<b>Attention:</b> $attention<br />";
    echo "<b>Message:</b> $message<br />";
    ?>
    </p>
    <table>
    <tr>
    <td>
    <form method="post" action="correspondence_submited.php">
    <input type="hidden" name="fname_second" value="<?php echo $fname;?>">
    <input type="hidden" name="surname_second" value="<?php echo $surname;?>">
    <input type="hidden" name="phone_second" value="<?php echo $phone;?>">
    <input type="hidden" name="fax_second" value="<?php echo $fax;?>">
    <input type="hidden" name="email_second" value="<?php echo $email;?>">
    <input type="hidden" name="busname_second" value="<?php echo $busname;?>">
    <input type="hidden" name="subject_second" value="<?php echo $subject;?>">
    <input type="hidden" name="attention_second" value="<?php echo $attention;?>">
    <input type="hidden" name="message_second" value="<?php echo $message;?>">
    <input type="submit" value="Send">
    </form>
    </td>
    <td>
    <form method="post" action="contact_us_edit.php">
    <input type="hidden" name="fname_second" value="<?php echo $fname;?>">
    <input type="hidden" name="surname_second" value="<?php echo $surname;?>">
    <input type="hidden" name="phone_second" value="<?php echo $phone;?>">
    <input type="hidden" name="fax_second" value="<?php echo $fax;?>">
    <input type="hidden" name="email_second" value="<?php echo $email;?>">
    <input type="hidden" name="busname_second" value="<?php echo $busname;?>">
    <input type="hidden" name="subject_second" value="<?php echo $subject;?>">
    <input type="hidden" name="attention_second" value="<?php echo $attention;?>">
    <input type="hidden" name="message_second" value="<?php echo $message;?>">
    <input type="submit" value="Edit">
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>[/code]


    correspondence_submited:
    [code=php]<?php

    if ($attention_second=='Manager') {
    $toaddress = "Email removed";

    } else if ($attention_second=='Aboriginal Enterprise Development Officer') {
    $toaddress = "Email removed";
    }
    $mailcontent = "Client Name: ".$fname_second." ".$surname_second."rn
    Phone: ".$phone_second."rn
    Fax: ".$fax_second."rn
    Email: ".$email_second."rn
    Company Name: ".$busname_second."rn
    Clients message: "."rn".$message_second;
    mail($toaddress, $subject_second, $mailcontent);
    ?>
    <html>
    <head>
    <title>
    Message has been sent.

    </title>

    </head>

    <body>

    <h1>This message has been sent.</h1>
    <?php
    echo "<b>First name:</b> $fname_second<br />";
    echo "<b>Surname:</b> $surname_second<br />";
    echo "<b>Phone:</b> $phone_second<br />";
    echo "<b>Fax:</b> $fax_second<br />";
    echo "<b>Fax:</b> $email_second<br />";
    echo "<b>Fax:</b> $busname_second<br />";
    echo "<b>Attention:</b> $attention_second<br />";
    echo "<b>to address:</b> $toaddress<br />";
    echo "<b>Subject:</b> $subject_second<br />";
    echo "<b>message:</b> $message_second<br />";
    ?>
    </body>
    </html>[/code]


    Notice the code has if statements:
    [code=php]if ($attention_second=='Manager') {
    $toaddress = "Email removed";

    } else if ($attention_second=='Aboriginal Enterprise Development Officer') {
    $toaddress = "Email removed";
    }[/code]

    hope that helps.
    Copy linkTweet thisAlerts:
    @tigerasyaauthorMar 02.2005 — Thank you guys for useful help.

    Thanks especially to Jona and Smercer for your help.

    You are great.

    Thanks a lot.

    Tigerasya
    Copy linkTweet thisAlerts:
    @JonaMar 02.2005 — [font=trebuchet ms]Happy to help.[/font]
    ×

    Success!

    Help @tigerasya spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...