How to Send E-Mail using PHP

Pin It


This article explains about sending a simple mail using PHP mail function.

Creating a Email Form using HTML

<form method="post" action="">
Sender Email: <input type="text" name="sender_email" size="18" />
Receipent Email: <input type="text" name="receipent_email" size="18" />
Mail Subject: <input type="text" name="email_subject" size="18" />
Email Message: <textarea name="message" rows="50" cols="6"></textarea>
<input type="submit" name="submit" value="Send Email" />
</form>

PHP Code For Handling Action and Send Email

if(count($_POST) > 0)
{
 $sender_email = $_POST["sender_email"];
 $receipent_email = $_POST["receipent_email"];
 $email_subject = $_POST["email_subject"];
 $message = $_POST["message"];
 $result = mail($receipent_email, $email_subject, $message,"From: $sender_email\n");
 if($result) {
    echo "Mail has been send successfully.";
 }
 else {
    echo "There was a problem in sending email.";
 }
}

This is just a method of how to send a simple email using PHP. In above script there is no way of proper error checking and other advance email functionalities like sending of HTML email, custom headers.

Submit your comment

Please enter your name

Your name is required

Please enter a valid email address

An email address is required

Please enter your message

Twitter

  • May 2, 2012 04:15

    10 Free WordPress Theme To Make You Forget About Premium Theme http://t.co/YRiLCiVa

  • March 2, 2012 17:16

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/FY0jh8Dn

  • March 2, 2012 16:43

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/QUlYKInf #IE #FF #Chrome #Testing #CrossBrowser

  • March 2, 2012 12:52

    Top 5 Plugins to Build Contact Form for WordPress http://t.co/PWyR08Iq #WordPress #Plugins #ContactForm

  • June 11, 2011 02:49

    CSS 3 Transitions http://bit.ly/m0pK3t

Design Gala © 2012 All Rights Reserved

Designed by 76miles

Powered by WordPress