PHP Mail Function

5 posts Page 1 of 1
Contributors
User avatar
wrighty1986
VIP - Donator
VIP - Donator
Posts: 119
Joined: Sat Sep 12, 2009 11:55 am

PHP Mail Function
wrighty1986
On this tutorial I will teach you the basics of creating a PHP/HTML Mail Form

First of all you must make sure MAIL is allowed on your server

okay, so the syntax we are going to be using will be.
Code: Select all
mail(to,subject,message,headers,parameters)
So the simple way for this is

PHP Code
Code: Select all
<?php 
//The email your sending the message to 
$to = "someone@example.com"; 

//The subject you wish to appear 
$subject = "Test mail"; 

//The message 
$message = "Hello! This is a simple email message."; 

//Who it's from 
$from = "someonelse@example.com"; 

//Define the headers 
$headers = "From: $from"; 

//The syntax (only this time using the variables to send) 
mail($to,$subject,$message,$headers); 

//Confirmation message 
echo "Mail Sent."; 
?> 
It's pritty easy really, the only 'difficult' bit would be remembering the syntax

This piece of code could be implimented into a registration system that sends a confirmation message to the user, or maybe a welcome email ectect.

You could use a HTML form in order to post information into the variables when sending the email to create a form, and then input jQuery to make it nicer/validation.
Back Aegean sorry not been on i.v just been moving.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: PHP Mail Function
mandai
You can also specify the mail server and the default sender address with this:
Code: Select all
ini_set("SMTP", "smtp.domain.com");
ini_set("sendmail_from", "user@domain.com");
User avatar
wrighty1986
VIP - Donator
VIP - Donator
Posts: 119
Joined: Sat Sep 12, 2009 11:55 am

Re: PHP Mail Function
wrighty1986
Cool mate will help sumone i hope thank's for addin to the code.
Back Aegean sorry not been on i.v just been moving.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: PHP Mail Function
mandai
I think this was posted previously.
Last edited by mandai on Sun Apr 29, 2012 9:16 pm, edited 1 time in total.
User avatar
natanspremo
Just Registered
Just Registered
Posts: 1
Joined: Fri Nov 12, 2010 7:17 pm

Re: PHP Mail Function
natanspremo
On every post that he makes,i see messages from other people that he copied sources from another pages...lol
Image
5 posts Page 1 of 1
Return to “Tutorials”