Thursday, November 12, 2009

Sending mails by PHP.

Most of the time people are struggling with mailing concept of PHP.
Here is an example to achieve this.

<form action="sendmail.php3" method="POST">
<input type="text" size="22" name="subject" value="MailContent">

< form action="sendmail.php3" method="POST">
< input type="text" size="22" name="subject" value="MailContent">

$to = "";
$from_header = "From: $from";
if($contents != "")
mail($to, $subject, $contents, $from_header);
header("Location: $HTTP_REFERER");
print("<HTML><BODY>Error, no comments were submitted!");

Here header("Location: $HTTP_REFERER"); will redirect back to the same url that visitor has came from.

It can be modified, incase if you wish to show any other url as follows.

header("Location: mailsucceed.html");

Sending HTML Email: Content-Type: text/html needs to be mentioned in case if you require to send a html email.

No comments:

Post a Comment


Obstacles are those frightful things you see when you take your eyes off your goal.------> by Henry Ford