php Mailform无法正常工作

时间:2011-03-29 14:52:47

标签: php webmail

我正在尝试使用mailform,这是我正在使用的代码..

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

<table class="mail" table width="400" border="0" align="center" cellpadding="0"    cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
<table class="mail" 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>Message</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"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html> 

这是运行的脚本..

<?php
// Contact subject
  $subject ="$subject";
  // Details
   $message="$detail";

   // Mail of sender
  $mail_from="$customer_mail";
  // From
  $header="from: $name <$mail_from>";

   // Enter your email address
   $to ="email";

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

   // Check, if message sent to your email
   // display message "thanks for sending us a message!"
  if($send_contact){
    Print "<html>";
    Print "<head>";
    Print "<link href='styles.css' rel='stylesheet' type='text/css' />";
    Print "</head>";
    Print "<body>";
    Print "<img src=images/banner2.png  alt='banner' />";
    Print "<p>Thanks for sending us a message!, please wait while you are being   redirected to the homepage</p>";
    Print "</body>";
    Print "</html>";

   }
   else {
   Print "<html>";
   Print "<head>";
   Print "<link href='styles.css' rel='stylesheet' type='text/css' />";
   Print "</head>";
   Print "<body>";
   Print "<img src=images/banner2.png  alt='banner' />";
   echo "ERROR";
   Print "</body>";
   Print "</html>";

  }
  ?>

当我发送电子邮件发送到“电子邮件”时,我只是从@localhost收到消息,我知道邮箱正在工作,因为我使用了不同的脚本,但我想使用这个脚本,因为我可以更改字体和大小。

感谢

2 个答案:

答案 0 :(得分:1)

看起来你正在尝试使用register_globals,但它被禁用(这是一件好事)。

您需要使用$_POS T来获取表单中的数据。

  $subject =$_POST['subject'];
      // Details
       $message=$_POST['detail'];

       // Mail of sender
      $mail_from=$_POST['customer_mail'];
 // From
  $header="from: ".$_POST['name']." <".$_POST['mail_from']>."";

   // Enter your email address
   $to =$_POST['email'];

答案 1 :(得分:0)

尝试将额外的-f参数用于mail(),以便将发件人地址指定为sendmail程序。

// To be certain, capitalize From:
$header="From: $name <$mail_from>";
$send_contact=mail($to,$subject,$message,$header, "-f$mail_from");