Page 1 of 1

PHP E-mailing Rate Topic: -----

#1 paperclipmuffin  Icon User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Posted 21 July 2009 - 12:14 AM

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.


First we shall make some code for sending a very simple email.
mail(<recipent>, <subject>, <message>);

In this example Alex is being notified that he needs to pay his bills:
mail("[email protected]", "Bills", "You need to pay water bill today.");

But what if you want a changeable message? We'll add a number for his debt:
$debt = 100;
mail("[email protected]", "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...
<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" />

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:

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:
<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'>
<input method="submit"/>

And then at send.php we have something neat:
//Here send a PM as normal
$main="You received a PM entitled: ";
$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:


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


Well, have fun, pay your bills, don't break your nose, wash the car, cook dinner and use PHP to send emails! Good luck!

Is This A Good Question/Topic? 0
  • +

Replies To: PHP E-mailing

#2 kewlkreator  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 39
  • View blog
  • Posts: 1,068
  • Joined: 25-March 09

Posted 25 September 2009 - 12:40 PM

Very nice. Shows how people make automated emails. :tup:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1