...

View Full Version : PHP Advanced Email Function



Lorinda
11-09-2012, 10:12 AM
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: :eek:


<!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: :eek:


<?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....:D

Thanking you in advance.:thumbsup:

Redcoder
11-09-2012, 08:42 PM
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?

Lorinda
11-12-2012, 04:48 AM
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 :)

Redcoder
11-13-2012, 08:13 PM
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

Lorinda
11-14-2012, 05:09 AM
Thak you very much. :thumbsup: I have read through the tutorials and worked on the following quote:


<?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. :confused:

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..:)

Redcoder
11-14-2012, 03:29 PM
Thak you very much. :thumbsup: I have read through the tutorials and worked on the following quote:



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?

tangoforce
11-14-2012, 03:35 PM
<?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.

Lorinda
11-15-2012, 05:11 AM
Awesome, thank you very much, it works. :thumbsup: :D

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 ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum