User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,331 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,380 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1903 | Replies: 3
Reply
Join Date: Jan 2006
Location: Land of Hope & Glory
Posts: 88
Reputation: j4mes_bond25 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
j4mes_bond25's Avatar
j4mes_bond25 j4mes_bond25 is offline Offline
Junior Poster in Training

Question PHP E-mail setting ???

  #1  
May 29th, 2006
After bending over backwards, I managed to finally get my form validation done, which seems working perfectly well.

After failing to work with e-mail, I wonder if anyone around could help me little towards e-mail so that as soon as someone presses "Submit" button, I get the entire form's message sent to me through an e-mail.

I've typed the e-mail related code right at the bottom of the form, although, I disabled the code so at least you can see the form since right now, it's showing some error message with the use of curly bracket ({).

I guess this e-mail related code should go somewhere up around the comment:
"// If there's NO error at all, along with displaying the filled fields"

I've typed in the comment all over the form, so as to make it easier to read & understand & knowing what's happening where.

I wish to receive the comment submitted on "j4mes_bond25@yahoo.co.uk".

Following is my "contact.php" code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Personal Website</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>

<body>
<?php // include("menu.inc");?>

<div id="centerContent">

<p>

<?php

// If the form has been posted, analyse it: 
if ($_POST) {
	foreach ($_POST as $field => $value) {
		$value = trim($value);
   	}

// Creating Variables
	$inquiry=$_POST['inquiry'];
	$title=$_POST['title'];
	$first_name=$_POST['first_name'];
	$last_name=$_POST['last_name'];
	$email=$_POST['email'];
	$phone=$_POST['phone'];
	$message=$_POST['message'];
	$reply=$_POST['reply'];
	$contact=$_POST['contact'];

// Create empty ERROR variables
	$error = ""; // for fields left BLANK
	$errorflag = ""; // for fields with INVALID data entered
	
// Check for field/fields that is/are left BLANK
	if (($first_name == "") || ($last_name == "") || ($email == "") || ($phone == "") || ($message == "")) {
		$error = "Please fill in all fields!";
	}
	else { 
	// Validate First Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered 
		if (ctype_alpha($first_name) == FALSE)  {
			$error = "Please enter a valid name <span class='italic'>(Alphabets only)</span>";
			$errorflag= "first_name";
			} 
	// Validate Last Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered 
		else if (ctype_alpha($last_name) == FALSE) {
			$error = "Please enter a valid last name <span class='italic'>(Alphabets only)</span>";
			$errorflag="last_name";
			} 
	// Validate E-mail (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered 
		else if ((strpos($email, "@") == FALSE)|| 
			(strpos($email, ".") == FALSE) ||
			(strpos($email, " ") != FALSE)) {
				$error = "Please enter a valid e-mail address";
				$errorflag="email";
			} 
	// Validate Contact No. (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered 
		else if (is_numeric($phone) == FALSE) {
			$error = "Please enter a valid contact number <span class='italic'>(must contain numbers only)</span>";
			$errorflag="phone";
			}
	} 
	// Confirmation Message seen AFTER filling the form and pressing "Submit" button (whether there's an error or not)
	if ($error != "") {	echo "<b><span class='colorText'>Error Occured: </b>" . $error."</span>" ; } // If there's an error along with displaying the list of flagged error/errors

// If there's NO error at all, along with displaying the filled fields
	else { echo "<p>Thanks for your comment and time. We will be in touch with you shortly.<br/><br/>"; 
		echo "<b>Nature of Inquiry:</b> ". $inquiry . "<br/>";
		echo "<b>Title:</b> ". $title . "<br/>";
		echo "<b>First Name:</b> ". $first_name . "<br/>";
		echo "<b>Last Name:</b> ". $last_name . "<br/>";
		echo "<b>E-mail:</b> ". $email . "<br/>";
		echo "<b>Contact No.:</b> ". $phone . "<br/>";
		echo "<b>Message:</b> ". $message . "<br/>";
		echo "<b>Reply:</b> ". $reply . "<br/>";
		echo "<b>Contact Method:</b> ". $contact . "<br/></p>";
	 	}
}
// DON'T KNOW WHY THERE'S "ELSE" CODE HERE
else {

	$inquiry = "";
	$title = "";
	$first_name = "";
	$last_name = "";
	$email = "";
	$phone = "";
	$message = "";
	$reply = "";
	$contact = "";
	$errorflag = "";
}

?>
</p>

<p class="first-letter">Please fill the following form in for any enquiries that you may have:</p>

<table id="contactTable">

<tr id="contactTr">
<td id="contactTd"><form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Nature of Enquiry:</td>
<td id="contactTd"><select name="inquiry">
<option <?php if ($inquiry == "General Inquiry") echo "Selected"; ?> value = "General Inquiry">General Inquiry</option>
<option <?php if ($inquiry == "Price Quotation") echo "Selected"; ?> value = "Price Quotation">Price Quotation</option>
<option <?php if ($inquiry == "Comments") echo "Selected"; ?> value = "Comments">Comments</option>
<option <?php if ($inquiry == "Other") echo "Selected"; ?> value = "Other">Other</option>
</select></td>
</tr>

<tr id="contactTr">
<td id="contactTd">Title:</td>
<td id="contactTd"><select name="title"/>
<option <?php if ($title == "Mr") echo "Selected"; ?> value = "Mr">Mr</option>
<option <?php if ($title == "Miss") echo "Selected"; ?> value = "Miss">Miss</option>
<option <?php if ($title == "Ms") echo "Selected"; ?> value = "Ms">Ms</option>
<option <?php if ($title == "Mrs") echo "Selected"; ?> value = "Mrs">Mrs</option>
<option <?php if ($title == "Other") echo "Selected"; ?> value = "Other">Other</option>
</select></td>
</tr>

<tr id="contactTr">
<td id="contactTd"><?php if ($errorflag == "first_name") { echo "<span class='colorText'>First Name:</span>"; } 
						else { echo "First Name:"; } ?></td>
<td id="contactTd"><input type="text" size="30" maxlength="30" name="first_name" value="<?php echo $first_name; ?>"/></td>
</tr>

<tr id="contactTr">
<td id="contactTd"><?php if ($errorflag == "last_name") { echo "<span class='colorText'>Last Name:</span>"; }
						else { echo "Last name:"; } ?></td>
<td id="contactTd"><input type="text" size="30" maxlength="30" name="last_name" value="<?php echo $last_name; ?>"/></td>
</tr>

<tr id="contactTr">
<td id="contactTd"><?php if ($errorflag == "email") { echo "<span class='colorText'>E-mail:</span>"; }
						else { echo "E-mail:"; } ?></td>
<td id="contactTd"><input type="text" size="30" maxlength="30" name="email" value="<?php echo $email; ?>"/></td>
</tr>

<tr id="contactTr">
<td id="contactTd"><?php if ($errorflag == "phone") { echo "<span class='colorText'>Contact No.:</span>"; }
						else { echo "Contact No.:"; } ?></td>
<td id="contactTd"><input type="text" size="30" maxlength="20" name="phone" value="<?php echo $phone; ?>"/></td>
</tr>

<tr id="contactTr">
<td id="contactTd">Message:</td>
<td id="contactTd"><textarea rows="10" cols="50" wrap="physical" name="message"/><?php echo $message; ?>
</textarea></td>
</tr>

<tr id="contactTr">
<td id="contactTd">Reply Required:</td>
<td id="contactTd"><input type="radio" name="reply" value="Yes" checked="checked"/>Yes
<input type="radio" name="reply" value="No" <?php if ($reply="No") echo "checked='checked'"; ?>/>No</td>
</tr>

<tr id="contactTr">
<td id="contactTd">How would you like to be contacted (if required)?<br/><br/></td>
<td id="contactTd"><input type="radio" name="contact" value="Email" checked="checked"/>E-mail
<input type="radio" name="contact" value="Telephone" <?php if ($contact="Telephone") echo "checked='checked'"; ?>/>Telephone
</td>
</tr>

<tr id="contactTr">
<td id="contactTd"></td>
<td id="contactTd"><input type="reset" name="reset" value="Reset">
<input type="submit" name="submit" value="Submit"></td>
</form>
</tr>
</table>

<?php 
/*
if ($_POST) {
	if (mail("j4mes_bond25@yahoo.co.uk", $_POST['inquiry'], stripslashes($_POST['message'], "From: " .$_POST['email']."r\n")) {
		echo "E-mail sent successfully";
}
elseif	{
echo "E-mail NOT sent";
	}
}
*/
?>

</div>
</body>
</html>
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 32
Reputation: BlazingWolf is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
BlazingWolf BlazingWolf is offline Offline
Light Poster

Re: PHP E-mail setting ???

  #2  
May 29th, 2006
You have to set what SMTP(Outgoing) Mail server you are going to user first. In order to set that use.

[php]ini_set(smtp, "mail.myserver.net");
ini_set(smtp_port, 25); //25 is the default leave it at that if you are unsure.
[/php]
Reply With Quote  
Join Date: Jan 2006
Location: Land of Hope & Glory
Posts: 88
Reputation: j4mes_bond25 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
j4mes_bond25's Avatar
j4mes_bond25 j4mes_bond25 is offline Offline
Junior Poster in Training

Question Re: PHP E-mail setting ???

  #3  
May 30th, 2006
Originally Posted by BlazingWolf
You have to set what SMTP(Outgoing) Mail server you are going to user first. In order to set that use.

[php]ini_set(smtp, "mail.myserver.net");
ini_set(smtp_port, 25); //25 is the default leave it at that if you are unsure.
[/php]


Do I set this SMTP Mail server in different file (if so, would it have ".php" extention ???) or do I simply type this code within the same file "contact.php".

By the way, may not be a rather sensible question but, instead of "myserver", do I change it to "apache" since that is the server I'm using for PHP OR do I leave it as "mail.myserver.net", as it's now.
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
Reply With Quote  
Join Date: Feb 2006
Posts: 32
Reputation: BlazingWolf is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
BlazingWolf BlazingWolf is offline Offline
Light Poster

Re: PHP E-mail setting ???

  #4  
May 30th, 2006
You want to leave those to lines in whatever files you are sending the mail in.

The mail.myserver.net is whatever your SMTP mail server is for instance mine is smtp.charter.net because charter is my hosting provider. If you use a email client like Outlook or Thunderbird you will have had to use this outgoing mail server address, so you can look it up in your settings.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC