Blog » PHP » send email using php

send email using php

This article will show you how to create send email using PHP mail function.this code is working on web hosting without change anything. If you have a xampp or wamp server you have to edit php.ini file and you can check script on your server.

here is the following details on php.ini file. its works fine.


SMTP = smtp.example.com
smtp_port = 25
username = information@example.com
password = youremailpassword
sendmail_from = information@example.com


Here is the Completed source code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sending mail</title>
</head>
<body>
<?php 
if($_SERVER['REQUEST_METHOD'] == "POST"){
$email = $_POST['txtEmail'];
$subject = $_POST['txtSubject'];
$message = $_POST['txtMessage'];
$message = wordwrap($message, 70);
if(mail($email,$subject,$message)){
echo "email sent successfully to $email<br/>";
}else{
echo "email sending failed";
}
}
?>
<form id="form" name="form" method="post" action="sendingmail.php">
Email:
<input name="txtEmail" type="text" id="txtEmail" />
<br />
Subject:
<input name="txtSubject" type="text" id="txtSubject" />
<br />
Message:
<textarea name="txtMessage" id="txtMessage"></textarea>
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
ARTICLE POSTED BY : Admin

Hi, I'am k.g uththara. I'm a professional web developer. I write blog posts in my free time. if you want to contact me, send a message on contact page, thanks.