Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy PHP Advanced Email Function

    Good Morning,

    I have a huge problem with some code in my site. I am creating a "Managers Login page" where the Head of the dept can allocate certain jobs to an specific user. I want the manager to complete the form and the system should send the form and hyperlink to the Dept Head.

    Here is the Form in HTML:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><style type="text/css"><!--body {background-image: url(SDM.png);background-color: #000;background-repeat: repeat-x;}.grey strong {color: #C0C0C0;}.Grey {color: #C0C0C0;}Grey {color: #C0C0C0;}--></style></head><body><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><form name="manspecification" action="post7.php" method="post">  <table align="center">  <td align="center">  <tr>        <td height="25" colspan="2" align="center" valign="middle"><h1 class="grey"><strong>Specifications</strong></h1>  <tr>          <td class="grey "><p class="Grey"> Allocated to User:          <td><select name="alloc">           <option value="s">MHAS002 - AS</option>                <option value="t">MHMS004 - MS</option>                <option value="u">MHMN005 - MM</option>                <option value="v">MHMW005 - MVW</option>                <option value="w">MHGC001 - GC</option>                <option value="x">MHGK002 - GDP</option>                <option value="y">MHLW009 - LW</option>                <option value="z">MHZP001 - ZP</option>                          </select>  <tr><td><tr>                <td class="grey"><p class="Grey">Allocated By:                <td><select name="allocby">                  <option value="a">LM</option>                  <option value="b">User</option>                  <option value="c">Other</option>                </select>  <tr><td><tr>                  <td class="grey"><p> <span class="Grey">Specification Information:</span>:                  <td>                        <label>                          <textarea name="specification" cols="75" rows="9" id="type"></textarea>                        </label>             <tr><td>                         <tr>                        <td class="grey"><p class="Grey"> Request number:<td><input name="reqno" type="text">                          <span class="Grey">A value is required.</span>  <tr><td>  <tr>          <td class="Grey">                                        Scheme:          <td><span class="Grey" id="sprytextfield3">          <input name="scheme" type="text" id="scheme" value="Medihelp">          A value is required</span>  <tr><td>                 <tr>                          <td class="Grey"><p>Date  Received:        <td><span class="Grey" id="fromtime">                          <input name="fromtime" type="text" value="yyyy/mm/dd 00:00:00">                          A value is required</span>  <tr>                                <td class="Grey"><p> Date Sent to User:<td class="Grey"><span id="sprytextfield2">                                <input name="totime" type="text" value="yyyy/mm/dd 00:00:00">                                A value is required</span><tr>                   <td class="Grey"><p class="Grey">Target Date                   :<td><span class="Grey">                   <input name="targetdate" type="text" value="yyyy/mm/dd 00:00:00" />  A value is required</span><tr>                                                <td class="grey"><p class="Grey"> Comments:          <td><textarea name="comments" cols="75" rows="7" id="comments"></textarea>  <tr>                                                  <td><p>                                                        <p>                                                          <input type="submit" value="Send">                                                          <input name="Reset" type="reset" value="Clear">  </table></body></html>
    and Now the PHP code:

    PHP Code:
    <?php$conn mysql_connect("localhost","root","root");$db       mysql_select_db("mysql",$conn);?><?php$alloc $_POST["alloc"];$allocby $_POST["allocby"];$specification $_POST["specification"];$reqno $_POST["reqno"];$scheme $_POST["scheme"];$fromtime $_POST["fromtime"];$totime $_POST["totime"];$targetdate $_POST["targetdate"];$comments $_POST["comments"];if($alloc == "s"){$alloc 'MHAS002 - AS';}else if ($alloc == "t"){$alloc 'MHMS004 - MS';}else if ($alloc == "u"){$alloc 'MHMN005 - MM';}else if ($alloc =="v"){$alloc 'MHMW005 - MVW';}else if ($alloc == "w"){$alloc 'MHGC001 - GC';}else if ($alloc == "x"){$alloc 'MHGK002 - GDP';}else if ($alloc == "y"){$alloc 'MHLW009 - LW';}else if ($alloc == "z"){$alloc 'MHZP001 - ZP';};if($allocby == "a"){$allocby 'LM';}else if ($allocby == "b"){$allocby 'User';}else if ($allocby == "c"){$allocby 'Other';};$sql     "INSERT into manspecification  values('$alloc','$allocby','$specification','$reqno','$scheme','$fromtime','$totime','$targetdate','$comments')";$query  mysql_query($sql);if(!$query)  echo mysql_error();else{  echo "Successfully Inserted<br />";  }?><p>&nbsp;</p><table border="0" cellspacing="0" cellpadding="3"><tr><td>Allocated To:<td><?=$alloc?><tr><td>Allocated By:<td><?=$allocby?><tr><td>Spec Info:<td><?=$type?><tr><Td>Request No:<td><?=$reqno?><tr><td>Scheme:<td><?=$scheme?><tr><td>From Time:<td><?=$fromtime?><tr><td>To Time:<td><?=$totime?><tr><td>Target Date:<td><?=$targetdate?><tr><td>Comments:<td><?=$comments?><td><td></td></table></form><p><A HREF="/manspesifications.html" target="_self"><strong>Go back</strong></A></p></body></html>
    wil anybody be able to assist me with this ? I have been struggling for a long time now?
    Please let me know if you can.

    P.S I am fairly new at PHP coding....

    Thanking you in advance.

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Remember to close the <form> tag with</form>.

    What is the problem exactly Sending the form by email , form submission
    displaying the form contents to the department head or what?

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi There,

    Thank you for responding. The problem is that I have tried to get the code right to get the mail to send in the first place. But it does not want to send, as a metter of fact it gives me an error if I add the code to the existing post7.php and also how do I get the system to allocate the email adress of the user ? As mentioned I am new at this and isn't doing to bad a job but only struggling with the emails.

    Scenario:

    Manger types the spec in on the system, allocates it to a specific user, the user then has to receive a mail with the hyperlink of where the specific spec is, the user then clicks on the hyperlink and completes the information that he/she has changed on the spec. This way the manager can track what the user has done on the spec. This will allow the manager also to make sure that the user does not change the spec number but only the times and what he/she has done.

    Does that make sence at all ?

    Can you please help me I have been struggling with this for almost a week

    Hope to hear from you soon

  • #4
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    To allocate the email of the user, the manager can type it directly and then you can have code that reads the values and inserts it into the mail function. Or you can have the email addresses stored in the database.

    For more info on mail() function, check out.

    http://php.net/manual/en/function.mail.php

    http://www.w3schools.com/php/php_mail.asp

  • #5
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thak you very much. I have read through the tutorials and worked on the following quote:

    PHP Code:
    <?php
    $conn 
    mysql_connect("localhost""root""root");
    $db mysql_select_db("mysql"$conn);
    ?>


    <?php

    if(isset($_POST['submit']))

    $alloc $_POST["alloc"];
    $allocmail $_POST["allocmail"];
    $allocby $_POST["allocby"];
    $specification $_POST["specification"];
    $reqno $_POST["reqno"];
    $scheme $_POST["scheme"];
    $fromtime $_POST["fromtime"];
    $totime $_POST["totime"];
    $targetdate $_POST["targetdate"];
    $comments $_POST["comments"];

    if (
    $alloc == "s") {
        
    $alloc 'MHAS002 - AS';
    } else
        if (
    $alloc == "t") {
            
    $alloc 'MHMS004 - MS';
        } else
            if (
    $alloc == "u") {
                
    $alloc 'MHMN005 - MM';
            } else
                if (
    $alloc == "v") {
                    
    $alloc 'MHMW005 - MVW';
                } else
                    if (
    $alloc == "w") {
                        
    $alloc 'MHGC001 - GC';
                    } else
                        if (
    $alloc == "x") {
                            
    $alloc 'MHGK002 - Gdp';
                        } else
                            if (
    $alloc == "y") {
                                
    $alloc 'MHLW009 - LW';
                            } else
                                if (
    $alloc == "z") {
                                    
    $alloc 'MHZP001 - ZP';
                                }
    ;

    if (
    $allocmail == "1") {
        
    $allocmail 'AS@xxxx.co.za';
    } else
        if (
    $allocmail == "2") {
            
    $allocmail 'MS@xxxx.co.za';
        } else
            if (
    $allocmail == "3") {
                
    $allocmail 'MM@xxxx.co.za';
            } else
                if (
    $allocmail == "4") {
                    
    $allocmail 'Mvk@xxxx.co.za';
                } else
                    if (
    $allocmail == "5") {
                        
    $allocmail 'GC@xxxx.co.za';
                    } else
                        if (
    $allocmail == "6") {
                            
    $allocmail 'GP@xxxx.co.za';
                        } else
                            if (
    $allocmail == "7") {
                                
    $allocmail 'LW@xxxx.co.za';
                            } else
                                if (
    $allocmail == "8") {
                                    
    $allocmail 'ZP@xxxx.co.za';
                                }
    ;

    if (
    $allocby == "a") {
        
    $allocby 'LM';
    } else
        if (
    $allocby == "b") {
            
    $allocby 'User';
        } else
            if (
    $allocby == "c") {
                
    $allocby 'Other';
            }
    ;

    $sql "INSERT into manspecification  values('$alloc','$allocmail','$allocby','$specification','$reqno','$scheme','$fromtime','$totime','$targetdate','$comments')";
    $query mysql_query($sql);

    if (!
    $query)
        echo 
    mysql_error();
    else {
        echo 
    "Successfully Inserted<br />";

    }
    ?>

    <?php

    if(isset($_POST['submit']))

    $Name $_POST['name']; //senders name
    $reqno $_POST['reqno'];
    $email $_POST['email']; //senders e-mail adress
    $allocmail $_POST['allocmail'];
    $mail_body $_POST['body']; //mail body
    $subject "Specification"//subject
    $header "From: 'SDM' "$Name " <" $email ">\r\n"//optional headerfields

    if ($allocmail == "1") {
        
    $allocmail 'AS@xxxx.co.za';
    } else
        if (
    $allocmail == "2") {
            
    $allocmail 'MS@xxxx.co.za';
        } else
            if (
    $allocmail == "3") {
                
    $allocmail 'MM@xxxx.co.za';
            } else
                if (
    $allocmail == "4") {
                    
    $allocmail 'Mvk@xxxx.co.za';
                } else
                    if (
    $allocmail == "5") {
                        
    $allocmail 'GC@xxxx.co.za';
                    } else
                        if (
    $allocmail == "6") {
                            
    $allocmail 'GP@xxxx.co.za';
                        } else
                            if (
    $allocmail == "7") {
                                
    $allocmail 'LW@xxxx.co.za';
                            } else
                                if (
    $allocmail == "8") {
                                    
    $allocmail 'ZP@xxxx.co.za';
                                }
                                
     {
    mail($allocmail$subject$mail_body$header$reqno); //mail command :)
    if (mail)
        echo 
    "Okay! We Can Proceed. Thank You !";
    else
        echo 
    "Sorry We Can't Proceed, Please Try After Some Time!";}
        
        

     
     
    ?>



    <p>&nbsp;</p>
    <table border="0" cellspacing="0" cellpadding="3">
    <tr><td>
    Allocated To:
    <td>
    <?= $alloc?>
    <tr><td>
    Allocated to Email:
    <td>
    <?= $allocmail?>
    <tr><td>
    Allocated By:
    <td>
    <?= $allocby?>
    <tr><td>
    Spec Info:
    <td>
    <?= $type?>
    <tr><Td>
    Request No:
    <td>
    <?= $reqno?>
    <tr><td>
    Scheme:
    <td>
    <?= $scheme?>
    <tr><td>
    From Time:
    <td>
    <?= $fromtime?>
    <tr><td>
    To Time:
    <td>
    <?= $totime?>
    <tr><td>
    Target Date:
    <td>
    <?= $targetdate?>
    <tr><td>
    Comments:
    <td>
    <?= $comments?>
    <td>


    <td>
    </td>


    </table>

    </form>


    <p><A HREF="/manspesifications.html" target="_self"><strong>Go back</strong></A></p>

    </body>
    </html>
    The user receives the email, but the data is not placed on the database and the screen saying successfully inserted does not pop up.

    Can you maybe tell me why I am getting this error or suggest something I can do to be able to place both these scripts into one php document ?

    Thnak you in advance..

  • #6
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Quote Originally Posted by Lorinda View Post
    Thak you very much. I have read through the tutorials and worked on the following quote:

    PHP Code:
            if ($allocby == "c") {
                
    $allocby 'Other';
            }
    //<---THIS SEMI-COLON?

    $sql "INSERT into manspecification  values('$alloc','$allocmail','$allocby','$specification','$reqno','$scheme','$fromtime','$totime','$targetdate','$comments')";
    $query mysql_query($sql); 
    See the Semi-colon problem in the above code comments.
    If it does not echo the success message, what does mysql_error() print out then?

  • Users who have thanked Redcoder for this post:

    Lorinda (11-15-2012)

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,309
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by Lorinda View Post
    PHP Code:
    <?php

    if(isset($_POST['submit']))
    Can I just take a moment to point you to my signature?

    The above line of code is known for being troublesome in IE. If you use a text box and the user hits enter then you're in for trouble. If you've no box and a user is forced to click the button then you'll be ok.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    Lorinda (11-15-2012)

  • #8
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Awesome, thank you very much, it works.

    Now all I have to try and do is get a hyperlink back to that specific form on the email ? You guys know how to do that ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •