I have a contact form. I need to deliver it to bala_palash@yahoo.com when anyone clicked on send. Please anyone help me...

My form is

<form name="contact_form" method="post" action="">
                  <table width="400" border="0">
                    <tr>
                      <td><label>Your Name (Required)<br>
                          <input class="name" name="name" type="text" id="name" value="" size="50">
                        </label></td>
                      </tr>
                    <tr>
                      <td><label>Your Email (Required)<br>
                          <input class="email" name="email" type="text" id="email" value="" size="50">
                        </label></td>
                      </tr>
                    <tr>
                      <td><label>Subject<br>
                          <input class="subject" name="subject" type="text" id="subject" value="" size="50">
                        </label></td>
                      </tr>
                    <tr>
                      <td><label>Your Message
                        <textarea class="message" name="message" cols="50" rows="10" id="message">

Recommended Answers

All 8 Replies

I've written a code for you.

<?php
If($_POST)
{
// Contact subject

$name=$_POST['name'];

$subject =$_POST['subject'];
$detail = $_POST['message'];
$mail_from=$name=$_POST['email'];
// Details
$message=" From: $name \n Subject : $subject \n Email : $mail_from \n Message : $detail ";


// Mail of sender
$mail_from=$name=$_POST['email'];

// From
$header="from: $name <$mail_from>";


// Enter your email address
$to ='bala_palash@yahoo.com';

$send_contact=mail($to,$subject,$message,$header);


// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}}
?>
<form name="form1" method="post" action="">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="500" border="0" cellspacing="0">
    <tr>
      <td>Your Name</td>
      <td><label>
        <input type="text" name="name" id="name">
      </label></td>
    </tr>
    <tr>
      <td>Your Email</td>
      <td><label>
        <input type="text" name="email" id="email">
      </label></td>
    </tr>
    <tr>
      <td>Subject</td>
      <td><label>
        <input type="text" name="subject" id="subject">
      </label></td>
    </tr>
    <tr>
      <td>Message</td>
      <td><label>
        <input type="text" name="message" id="message">
      </label></td>
    </tr>
  </table>
  <p>
    <label>
    <input type="submit" name="button" id="button" value="Submit">
    </label>
  </p>
</form>

See first of all your server must have SMTP support otherwise you can't send mail.
First checks that.If it supports SMTP then check mail method of php.
Click Here.
Syntax is :
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

So in your case it would be somethink like this:-

<?php
If($_POST)
{
// Contact subject
$name=$_POST['name'];
$subject =$_POST['subject'];
$detail = $_POST['message'];
$mail_from=$name=$_POST['email'];
// Details
$message= $detail;//you can format message  as the header content type is html.So you can add HTML tags
// Mail of sender
$mail_from=$name=$_POST['email'];
// From
$headers = "From: ". $_POST['to'] . "\r\n" .
            "Content-type: text/html; charset=UTF-8" . "\r\n".
// Enter your email address
$to ='bala_palash@yahoo.com';
$send_contact=mail($to,$subject,$message,$headers);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}}
?>
<form name="form1" method="post" action="">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="500" border="0" cellspacing="0">
    <tr>
      <td>Your Name</td>
      <td><label>
        <input type="text" name="name" id="name">
      </label></td>
    </tr>
    <tr>
      <td>Your Email</td>
      <td><label>
        <input type="text" name="email" id="email">
      </label></td>
    </tr>
    <tr>
      <td>Subject</td>
      <td><label>
        <input type="text" name="subject" id="subject">
      </label></td>
    </tr>
    <tr>
      <td>Message</td>
      <td><label>
        <input type="text" name="message" id="message">
      </label></td>
    </tr>
  </table>
  <p>
    <label>
    <input type="submit" name="button" id="button" value="Submit">
    </label>
  </p>
</form>

this code snippet is written with dirty values? why write code for semeone and allow dirty values in one of the most vulnerable of php functions?
sanitize the post values or suffer the consequences.

this code snippet is written with dirty values? why write code for semeone and allow dirty values in one of the most vulnerable of php functions?
sanitize the post values or suffer the consequences.

this code snippet is written with dirty values? why write code for semeone and allow dirty values in one of the most vulnerable of php functions?
sanitize the post values or suffer the consequences.

This is very true.

Although the majority of code snippets you will get will require you to add code sanitizing.

Thanks a lot

Or, if it helps, then here is a code I use;

<?php
require("class.phpmailer.php");
    $email = $_POST['email'];
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "localhost";
    $mail->From = "source_email@domain.com";
    $mail->FromName  =  "Your_name";
    $mail->AddAddress("recipient_1@domain.com");
    //$mail->AddAddress("recipient_2@domain.com");
    $msg = "This is the sample message";
    $subject = "My first Email";
    $mail->SMTPAuth = "true";
    $mail->Username = "your_gmail_account@gmail.com";
    $mail->Password =  "your_gmail_password";
    $mail->Port  =  "25";

    $mail->Subject = $subject;
    $mail->Body = $msg;
    $mail->WordWrap = 50;

    if(!$mail->Send())
    {
        echo 'Message was not sent.';
        echo 'Mailer error: ' . $mail->ErrorInfo;
    }
    else
    {
        echo 'Mail has been sent.';
    }

?>

This will only work on condition that you have uncompressed phpMailer and this file is within the same folder as the extracted phpMailer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.