I 've always used the mail function http://us.php.net/mail to send text email from a website. Is there a way people are familiar with to send html as the message content and have it display properly.
how to send html email with mail() function
You can just include html in the content that you pass to the mail() function with no problem.
In general though, the mail() function is quite limited in what it can do. There are a ton of free libraries out there that offer more power. One I have had good luck with is PHPMailer. It's free and open source. You might want to give that a try if you can't get mail() to do what you want.
There is a little bit more to it than just including html when sending with mail(). Here is a tutorial on it http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php#html
Hi im new to php programming and i just need a simple mail to send users passwords if they have forgotton their passwords, all i need is their email and user name to authenticate them and the email should be sent to the email address registered. How would i go about programming this, do i need a mail server? Thanks in advance.
mjgdunne wrote:Hi im new to php programming and i just need a simple mail to send users passwords if they have forgotton their passwords, all i need is their email and user name to authenticate them and the email should be sent to the email address registered. How would i go about programming this, do i need a mail server? Thanks in advance.
You don't need a mail server. If you are storing user info in a database, then you can just query the database for the user with the email and user name fields matching what they input into a form. If there is a record that exists matching, then you could write a script to email them.
Thats great thanks, i put together some code, could you tell me if it is right and what else i may need to incorporate in it to get it to work for me.
Any advice would be greatly appreciated. Thanks.
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from signup form
$myusername=$_POST['myusername'];
$myemail=$_POST['myemail'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and email='$myemail'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $myemail, table row must be 1 row
if($count==1){
$sql="SELECT * FROM $tbl_name WHERE email = '$myemail'";
$resultID=mysql_query($sql);
$row = mysql_fetch_array($resultID);
$password = $row[0];
In this case, you could just use the php mail() function to send the password.
http://www.php.net/manual/en/function.mail.php