【问题标题】:email form adding a phone number [closed]添加电话号码的电子邮件表格[关闭]
【发布时间】:2014-01-29 11:07:41
【问题描述】:

我的联系页面上有这个表格:

    <?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $phone = $_REQUEST['phone'] ;
  $message = $_REQUEST['message'] ;
  mail("contact@*****.com", $name, 
  $message, "From:" . $email);
  echo "Thank you for using our mail form. <br><br>We will get back to you within 48 hours.";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<br><form method='post' action='enquiry.php' align='center'>
  <strong>Name: </strong><input class='textbox' name='name' type='text'><br><br>
  <strong>Email: </strong><input class='textbox' name='email' type='text'><br><br>
  <strong>Phone: </strong><input class='textbox' name='phone' type='text'><br><br>
  <strong>Message: </strong><br>
  <textarea class='textbox' name='message' rows='15' cols='40'>
  </textarea><br>
  <input type='submit'><br><br>
  </form>";
  }
?>

当有人提交表单时,它会向我发送一封电子邮件。

但是当我尝试将$phone 添加到我的电子邮件代码时。它无法将邮件发送给我。

有人可以告诉我在哪里可以添加这个吗?谢谢你。

【问题讨论】:

  • 确保打开了 php 错误。还要发布您如何在代码中添加$phone
  • 显示两个不同的代码,用于两种不同的情况
  • 您之前在哪里添加了您的电话号码 ($phone)?你能解释一下吗。你的问题不是很清楚。

标签: php forms email contact


【解决方案1】:

这样做:

$message = $_REQUEST['message'].$phone;

这将在您的消息中附加手机号码。

【讨论】:

    【解决方案2】:

    那么有什么问题,在发送之前将数字附加到 $message。

    $message .= $phone;
    

    【讨论】:

    • 对不起,我没有关注你。我把那个代码放在哪里?我是 php 新手。
    【解决方案3】:

    试试看

    <?php
    if (isset($_REQUEST['email'])) //if "email" is filled out, send email
    {
          //send email
          $name = $_REQUEST['name'] ;
          $email = $_REQUEST['email'] ;
          $phone = $_REQUEST['phone'] ;
          $message = $_REQUEST['message'] ;
    
          $message_text = $message." Phone no:".$phone; // combine here $message and $phone to $message_text
    
          mail("contact@*****.com", $name, $message_text, "From:" . $email); // now use $message_text here to send mail
          echo "Thank you for using our mail form. <br><br>We will get back to you within 48 hours.";
    }
    else //if "email" is not filled out, display the form
    {
          echo "<br><form method='post' action='enquiry.php' align='center'>
          <strong>Name: </strong><input class='textbox' name='name' type='text'><br><br>
          <strong>Email: </strong><input class='textbox' name='email' type='text'><br><br>
          <strong>Phone: </strong><input class='textbox' name='phone' type='text'><br><br>
          <strong>Message: </strong><br>
          <textarea class='textbox' name='message' rows='15' cols='40'>
          </textarea><br>
          <input type='submit'><br><br>
          </form>";
     }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 2014-02-12
      相关资源
      最近更新 更多