PHP表单字段不会发送到电子邮件 [英] PHP Form fields will not send to email

查看:134
本文介绍了PHP表单字段不会发送到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个发送电子邮件到PHP脚本。

I have created a send to email PHP script.

当发送只有一个字段(消息字段)时,表单似乎工作正常,但其他字段被添加后,表单不再通过电子邮件发送到收件箱(但表单仍然正确激活并重新路由到thankyou就好了)。

The form seems to work correctly when sending only one field (the message field) but as soon as other fields are added, the form ceases to be emailed on to the inbox (yet the form still fires correctly and reroutes to the thankyou just fine.)

这里是我目前的代码

Here is the code I currently have, this does not work

<?php
  $email = $_REQUEST['email'] ;
  $name = $_REQUEST['name'] ;
  $services = $_REQUEST['services'] ;
  $message = $_REQUEST['message'] ;

  if (!isset($_REQUEST['email'])) {
    header( "Location: feedback.html" );
  }
  elseif (empty($email) || empty($message)) {
     header( "Location: error.html" );
 }
  else {
    mail( "info@website.co.uk", "Message via your website!",
           $name, $services, $message, "From: $email" );
    header( "Location: thankyou.html" );
  }
?>

这是前面的代码,这是行得通的,但只显示消息

This is the previous code, this does work, but only displays the message

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  if (!isset($_REQUEST['email'])) {
    header( "Location: feedback.html" );
  }
  elseif (empty($email) || empty($message)) {
     header( "Location: error.html" );
 }
  else {
    mail( "info@website.co.uk", "Message via your website!",
          $message, "From: $email" );
    header( "Location: thankyou.html" );
  }
?>

这是表单的HTML:

<form method="post" action="sendmail.php">
    <label>Name:</label> <input name="name" type="text" /><br />
    <label>Email:</label> <input name="email" type="text" /><br />
    <label>What service do you require?:</label>  <input name="services" type="text" /><br />
    <label>Message:</label><br />
    <textarea name="message" rows="15" cols="40">
    </textarea><br />
    <input type="submit" />
</form>


推荐答案

根据 mail()文档邮件正文应作为单个参数传递。所以它应该看起来更像是:

As per the mail() docs the message body should be passed as a single parameter. So it should look something more like:

mail( "info@website.co.uk", "Message via your website!", "$name\r\n $services\r\n $message", "From: $email");

这篇关于PHP表单字段不会发送到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆