PDA

View Full Version : Sending Email with php


scoutt
06-15-2005, 01:15 PM
I have seen this more and more often. some of you want to send emails to you or another address. well in php is it way easy.

to start we need a form, this will do

<form action="test.php" method="post">
<input type="text" values="" name="myname">
<input type="submit" value="Submit" name="submit">
</form>

this will allow the user to enter a name in the form and have it submit to your email. now we don't neccassarily hav eto stop at a name so you can add more if you want.

so the page it submits to text.php will look like this

<?php
$name = $_POST['myname'];
$message = "this the body of the email, Hi, $name";
$subject = "this is the subject of the email";
$headers = "From: you@someplace.com <you@someplace.com>\r\n";
mail("your@email.com",$subject,$message, $headers);

very basic email, text only. if you want html email it is just a little more added.

<?php
$name = $_POST['myname'];
$message = "<html><head></head><body><br /><br />";
$message .= "this the body of the email, Hi, $name";
$message .= "<br /></body></html>";
$subject = "this is the subject of the email";
$headers = "From: you@someplace.com <you@someplace.com>\r\nContent-type: text/html";
mail("your@email.com",$subject,$message, $headers);

of course there is a lot more you can add to that but that will send a very basic html email, pretty simple. :)

for more information on email you can read up on it here: mail() (http://www.php.net/manual/en/ref.mail.php)