Log in

View Full Version : PHP Mail()



GiGalo
04-18-2012, 12:57 PM
I am having two problems with contact since I converted my pages to template format. The first problem is the form is broken. I am able to send the mail to a static address but the email address collected on the form is not showing in the from section of the email, nor does the email show in the reply. The second issue after suibmitting the page returns to the index which is the main template that all pages resolve through. I want to simply have the form verify that a message was sent throught the existing template.

I have tried multiple things with no sucess on the email problem. Here is the original code I started with before attempts:


<?php
$message = $_GET['usr_find'];
$message .= $_GET['message'];

$reason = $_GET['reason'];
$email = $_GET['email'];


$admin = "admin email";
$bigtime = "site email";


function sendMail($reason, $email, $message, $admin, $bigtime )
{

if ($reason == "feedback")
{
mail($admin, $reason, $message, $email);
return true;
}

if ($reason == "interested")
{
mail($bigtime, $reason, $message, $email );
return true;
}
}



function showForm(){

print <<<_HTML_

<form id="contact" enctype="text/plain" method="GET" name="contact" action="$_SERVER[PHP_SELF]" onsubmit="return validateForm()">

<fieldset><legend style="color: rgb(0, 0, 0)">Please
use this form to Contact Us:</legend>
<table class="formTable">
<tbody>
<tr>
<td>Your Email Address:&nbsp;<input size="30" name="email" type="text"></td>
</tr>
<tr>
<td>Reason for contact:
<select name="reason">
<option selected="selected" value="not_selected">-Please select one-</option>
<option value="feedback">Site Feedback or Problems</option>
<option value="interested">interested in Service</option>
</td>
</tr>
<tr>
<td>How did you find us:
<select name="usr_find">
<option selected="selected" value="not_selected">-Please select one-</option>
<option value="friend:">Reccomended by Friend</option>
<option value="internetSearch:">Internet Search</option>
</select>
</td>
</tr>
<tr>
<td>Your Message:<br>
<textarea maxsiz="200" name="message" cols="60" rows="10" id="message"></textarea></td>
</tr>
<tr>
<td> <input name="submit" type="submit">
</td>
</tr>
</tbody>
</table>
</fieldset>
</form>
_HTML_;
}

if (isset($_GET['submit'])) {
sendMail($reason, $email, $message, $admin, $bigtime );
echo 'We have successfully recieved your mail. Thank You';

}else{
showForm();
}
?>

GiGalo
04-18-2012, 02:37 PM
I was able to fix my email problem. The only problem remaining is the template issue. How do I feed the processContact.php page, that I created to fix email issue, through the template. When I hit submit on the contact.php page the template does not show on the process page. Only the echo statement that says thank you for submitting.

Here is the template code that I used to display content section of said page [p] which is defined from an array of links to each contet page



<div id="content">
<?php
$default = 'home'; //Whatever default page you want to display if the file doesn't exist or you've just arrived to the home page.
$page = isset($_GET['p']) ? $_GET['p'] : $default; //Checks if ?p is set, and puts the page in and if not, it goes to the default page.
$page = basename($page); //Gets the page name only, and no directories.
if (!file_exists('scrps/'.$page.'.php')) { //Checks if the file doesn't exist
$page = $default; //If it doesn't, it'll revert back to the default page
//NOTE: Alternatively, you can make up a 404 page, and replace $default with whatever the page name is. Make sure it's still in the inc/ directory.
}

include('scrps/'.$page.'.php'); //And now it's on your page!



?>
</div> <!-- end #content -->

GiGalo
04-18-2012, 03:07 PM
I have resolved my problem.