php 邮件表单无法正常工作

发布于 2024-10-27 21:58:39 字数 2898 浏览 1 评论 0原文

我正在尝试让邮件表单正常工作,这是我正在使用的代码..

<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的消息,我知道邮箱正在工作,因为我使用了不同的脚本,但我想使用这个脚本,因为我可以更改字体和大小。

谢谢

I'm trying to get a mailform working, this is the code im using..

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

this is the script that runs..

<?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>";

  }
  ?>

when I put my email in 'email' when it sends I just get a message from @localhost, I know the mailbox is working as I used a different script, but I would like to use this script as I can change font and size.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑,眼淚并存 2024-11-03 21:58:39

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

您需要使用 $_POST 从表单中获取数据。

  $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'];

It looks like you're trying to use register_globals, but it's disabled (which is a good thing).

You need to get the data from the form using $_POST instead.

  $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'];
夜雨飘雪 2024-11-03 21:58:39

尝试使用 mail() 的附加 -f 参数来指定 sendmail 程序的发件人地址。

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

Try using the additional -f parameter to mail() in order to specify the From address to the sendmail program.

// To be certain, capitalize From:
$header="From: $name <$mail_from>";
$send_contact=mail($to,$subject,$message,$header, "-f$mail_from");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文