0
votes

I want create mail form in php. I write the html code for ny form.I write the html form and the php code in the same file. So i dont want to use another file for email sending.

    <div class="agent-contact">
      <table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
      <tr>
      <td><strong>Contact Form </strong></td>
      </tr>
      </table>

      <table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
        <tr>
          <td>
            <form name="form1" method="post" action="">
              <table width="100%" border="0" cellspacing="1" cellpadding="3">
                <tr>
                  <td width="16%">Subject</td>
                  <td width="2%">:</td>
                  <td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
                </tr>
                <tr>
                  <td>Detail</td>
                  <td>:</td>
                  <td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
                </tr>
                <tr>
                  <td>Name</td>
                  <td>:</td>
                  <td><input name="name" type="text" id="name" size="50"></td>
                </tr>
                <tr>
                  <td>Email</td>
                  <td>:</td>
                  <td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td><input type="submit" name="Submit" value="Send Message"></td>
                </tr>
              </table>
            </form>
          </td>
        </tr>
      </table>
  </div>

my php code for sending the mail is

<?php

$subject ="$subject";

$message="$detail";

$mail_from="$customer_mail";

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


$to ='[email protected]';

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


if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROffR";
}

?>

How i send the mail when submit the send message button ? I have the same file.

1
use the class phpmailer phpmailer.worxware.comAlessandro Minoccheri
also read PHP: Dealing with Formuser1646111
You'd be better off in the long run using a PHP mail library such as Zend_Maildjskinner

1 Answers

0
votes

use isset

if($_POST['submit']) {
  $subject =$_POST['subject'];

  $message=$_POST['detail'];

  $mail_from=$_POST['customer_mail'];

  $header="from: " . $_POST['name'] ." <$mail_from>";


  $to ='[email protected]';

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


  if($send_contact){
    echo "We've recived your contact information";
  }
  else {
     echo "ERROffR";
  }
 }