Step 1:

First set up your testing server and local server to point to the same folder, and set your URL prefix.

 

Step 2:

Create your .php file in that folder and name it anything you want.

 

 

Step 3:

Go ahead and format it any way you want using CSS. Be sure to give it Your Name: Your Message: and text fields for each.

 

Step 4:

Make sure it has a submit button. (You can also include a drop down menu for HTML or Plain Text if you like.

 

Step 5:

Start by typing your mail command with a to, subject, and message rapped in the <?php ?> tag:

mail ($recip, $subject, $finalMessage)

 

Step 6:

Then give values to your three variables such as:

$recip = 'trickorblog@yahoo.com';

$subject = 'My first email';

$finalMessage = 'This is your actual message area';

Step 7:

As set up now, once you preview in the browser, it will send the mail. Each time you preview the page, it will also send an email. However, there is nothing on the page to let you know it is working. Lets add something to our page to show us if the email is functioning properly.

 

Step 8:

Wrap the mail function in a conditional and echo back text so you know if it has or has not been processed.

if ( mail ($recip, $subject, $finalMessage) )

{

echo 'Your message was sent successfully';

}

else

{

echo 'There was an error in sending your message. Try again';

}

Step 9:

Now we want to customize the look of the email that is sent. Grab the headers code (from 02MailHeaders.php file). Paste them into your .php doc above the mail section next to your previous variables.

 

Step 10:

This is the shorthand advanced way of doing concatenation. The \r\n is code for return new line. This makes things move down the page.

 

Step 11:

You can change the X sender to your own personal email address. Example:

$headers .= "X-Sender: nikkiblade68@yahoo.com\r\n";

Step 12:

You can also change the From portion to be more personal such as:

$headers .= 'From: Nikki's Email Account<nikkiblade68@yahoo.com>' . "\r\n";

Step 13:

Now add the $headers variable to your mail function:

if ( mail ($recip, $subject, $finalMessage, $headers) )

Step 14:

You can change your final message by putting it on more than one line by using concatenation.

$finalMessage = '<h1>Hello</h1>';

$finalMessage .= 'This is an <strong>HTML</strong> message';

$finalMessage .= 'Sincerely, <br/> Nikki';

Step 15:

The formatting above will only work if you've set the content type to text/html. (If you want plain text you can just uncomment it out and comment out the html line).

 

Step 16:

Now that the email is set up and working, we need to change the script so it only works when we use our form.

 

Step 17:

With the property inspector up, set the Your Name: text field to "username".

 

 

Step 18:

Set the Your Message: text field to "usermessage".

 

 

Step 19:

In our example, set the dropdown bar to "contentType".

 

 

Step 20:

Set the submit button name to "submit", and the value to "Send Us A Message".

 

 

Step 21:

Select the form tag from the breadcrumbs, then in the Actions area, point it back to the same document you are working in.

 

Step 22:

Make sure the Method is set to POST.

 

 

Step 23:

Now we need to run a conditional to see if the form has been sent. Above all your variables add:

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

{

Step 24:

Now select all your php under that and tab to move it in a bit.

 

 

Step 25:

Then add one more } at the bottom to close out the if statement.

 

 

Step 26:

At this point it will work whether or not you fill anything in. Now we just need to plug in the variables.

 

Step 27:

Under the if bracket above, we are going to create all three variables used in the form:

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

{

$username = $_POST['username'];

$usermessage = $_POST[usermessage];

$contentType = $_POST['contentType'];

Step 28:

Now we can use concatenation to set the username in the From section of our email.

$headers .= 'From: ' . $username . ' <nikkiblade68@yahoo.com>' . "\r\n";

 

 

Step 29:

We can also set up the usermessage such as:

$finalMessage = $usermessage;

 

Step 30:

We can also wrap the dropdown in a condition so we know whether its html or plain text they prefer. Above the content type, type the following in:

if (contentType == 'html ')

{

$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

}

else

{

$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";

}

Step 31:

We can customize the message further by adding the following:

$finalMessage = 'The following was sent from the web form: ';

$finalMessage .= $usermessage;

$finalMessage .= 'Sincerely, <br/>' . $username;

Step 32:

Finally, we can take the $finalMessage and put it in the conditional under the $headers section. (See the 01phpEmail.php document for the final example.

 

Step 33:

This is the very basic way to set up the emails. The 03 folder has more complete information and you can always use php.net to find out more.