0

我想在 php 中创建邮件表单。我为 ny 表单编写 html 代码。我将 html 表单和 php 代码编写在同一个文件中。所以我不想使用另一个文件发送电子邮件。

    <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>

我发送邮件的 php 代码是

<?php

$subject ="$subject";

$message="$detail";

$mail_from="$customer_mail";

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


$to ='someone@somewhere.com';

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


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

?>

提交发送消息按钮时如何发送邮件?我有相同的文件。

4

1 回答 1

0

采用isset

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

  $message=$_POST['detail'];

  $mail_from=$_POST['customer_mail'];

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


  $to ='someone@somewhere.com';

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


  if($send_contact){
    echo "We've recived your contact information";
  }
  else {
     echo "ERROffR";
  }
 }
于 2013-02-27T11:33:11.360 回答