1,105,625 Community Members

Contact Form Submission

Member Avatar
pol.bala
Newbie Poster
9 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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">
Member Avatar
radow
Junior Poster in Training
73 posts since Oct 2012
Reputation Points: 7 [?]
Q&As Helped to Solve: 18 [?]
Skill Endorsements: 1 [?]
 
0
 

You must will implement php script, which be get data and send on mail.
For send mail you may use function mail http://www.php.net/manual/en/function.mail.php or PHPMailer http://phpmailer.worxware.com/index.php?pg=tutorial.

Member Avatar
Shalomd
Light Poster
38 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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>
Member Avatar
IIM
Master Poster
742 posts since Jun 2011
Reputation Points: 163 [?]
Q&As Helped to Solve: 169 [?]
Skill Endorsements: 24 [?]
 
0
 

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>
Member Avatar
moneeshot
Light Poster
33 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
Squidge
Posting Pro in Training
476 posts since Dec 2009
Reputation Points: 101 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 6 [?]
 
0
 

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.

Member Avatar
Webville312
Posting Whiz
367 posts since Feb 2012
Reputation Points: 14 [?]
Q&As Helped to Solve: 34 [?]
Skill Endorsements: 0 [?]
 
0
 

Use PHPMailer to send the email. It works for me. Here is the link;

https://code.google.com/a/apache-extras.org/p/phpmailer/

Member Avatar
pol.bala
Newbie Poster
9 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks a lot

Member Avatar
Webville312
Posting Whiz
367 posts since Feb 2012
Reputation Points: 14 [?]
Q&As Helped to Solve: 34 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: