...Technology Simplified

Monday, May 21, 2012

How to send email in PHP

No comments :
index.html


<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<center>
<table border="1" bgcolor="red">
<tr>
<td>
<form name="form" method="post" action="mail.php">
<center>To: <input type="text" name="to"><br></center>
<center>From: <input type="text name="from"><br></center>
<center>Subject: <input type="text" name="subject"><br></center>
<center>Message:<br><textarea name="message" rows=4 cols=25></textarea></center><br>
<center><input type="submit" value="send"></center>
</td>
</tr>
</body>
</html>


mail.php


<?php
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST ['from'];
$headers = "From: $from";
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","emailserver.sample.data.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('anuradha@xyz.com', 'anuradha@xyz.com');

$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['from']) . "</td></tr>";
$message .= "<tr><td><strong>Comments:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";


$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>




No comments :

Post a Comment