School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,104 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,056 people online right now. Registration is fast and FREE... Join Now!




PHP E-mailing

 
Reply to this topicStart new topic

> PHP E-mailing

paperclipmuffin
Group Icon



post 20 Jul, 2009 - 11:14 PM
Post #1


Hi, and welcome to my tutorial.

Being able to send emails automatically is very useful. You can remind site users about something or notify them of an event.

IMPORTANT: THIS CODE IS NEVER TO BE USED FOR MALICIOUS PURPOSES, E.G SPAMMING.

First we shall make some code for sending a very simple email.
SYNTAX:
CODE

mail(<recipent>, <subject>, <message>);

In this example Alex is being notified that he needs to pay his bills:
CODE

mail("alex@somemail.com", "Bills", "You need to pay water bill today.");

But what if you want a changeable message? We'll add a number for his debt:
CODE

$debt;
$debt = 100;
mail("alex@somemail.com", "Bills", "You owe Faketown water " $debt);

That's all very good, but what if you want a user to be able to edit what goes in the email? We'll add a HTML form...
CODE

<form action="send.php" method="post">
From: <input type="text" name="fname" />
Subject: <input type="text" name="age" />
Body: <br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type="submit" />
</form>

Then you would feed that into an email code like the ones you just learnt at send.php using $_post. This is great for customer feedback form, ect.

If you want to stop people spamming you through these form (which is a very good idea) you could add an image captcha from: reCAPTCHA. This link is not spam.gif

Remember how earlier I told you about notifying users of a site about events? Well here is the bit that tells you about that. (P.S: For this bit you will need to know how to use MySQL.)

Let's say we want a user to be notified of a PM being sent to him/her. Once again we will use Alex as our example (he's probably getting a bit tired of this PHP stuff). We have a very simple PM form:
CODE

<form action="send.php" method="post">
Send a PM <br />
To: <input type="text" name="to">
Title: <input type="text" name="title">
Message: <br />
<textarea name='message' rows='15' cols='40'>
</textarea>
<input method="submit"/>
</form>

And then at send.php we have something neat:
CODE

//Here send a PM as normal
$main="You received a PM entitled: ";
$title=$_post["title"];
$recipient=//Here you will have to get the recipient email from a MySQL database;
$all=$main.$title; //Fuse the 2 together
mail($recipient, "New PM", $all);

And if you do that right, the PM recipient would receive an email something like:
QUOTE

You received a PM entitled: Your tut was not approved.


Cool!

Well, have fun, pay your bills, don't break your nose, wash the car, cook dinner and use PHP to send emails! Good luck!
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

kewlkreator
Group Icon



post 25 Sep, 2009 - 11:40 AM
Post #2
Very nice. Shows how people make automated emails. thumbs-up.gif
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 12:37PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month