PHP表单消息 [英] PHP Form Message

查看:107
本文介绍了PHP表单消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个表单:

<form method="post" action="contactus.php?message=ok" name="myForm" autocomplete="off">
    <label for="Name">Name:</label>
    <input type="text" name="Name" id="Name" maxlength="60" required/>

    <label for="email">Email:</label>
    <input type="text" name="email" id="email" maxlength="120" required/>

    <label for="message">Message:</label><br />
    <textarea name="message" rows="20" cols="20" id="message" required></textarea>

    <input type="submit" name="submit" value="Submit" class="submit-button" onsubmit="displayMessage()" />

发送电子邮件的代码:

<?php 
if($_POST["submit"]) { 
  // The message
  $message=$_POST["message"];   
  $email=$_POST["email"];
  // In case any of our lines are larger than 70 characters, we should use    wordwrap()
  $message = wordwrap($message, 70, "\r\n");
  // Send
  mail('myemail.co.uk', $email, $message);
  $sent_mail = true;
}
?>

最后:

<?php
if (isset($sent_mail)) {
  echo 'Thank you. We will be in touch soon.';
}
?>

所以当发送电子邮件时,sent_mail设置为true,因此感谢信息应该回应。但现在这是不行的。电子邮件首先发送,但谢谢信息不显示。我基本上只需要一个谢谢信息,当提交按钮被按下时,页面上的某个地方。

So when the email is sent, sent_mail is set to 'true' and therefore the thank you message should be echoed. But right now this isn't working. The email sends first but the thank you message doesn't show. I basically just need a thank you message to come up somewhere on the page when the submit button is pressed.

任何想法?

推荐答案

mail 函数返回一个布尔值(true / false),所以你可以这样做

mail function returns a boolean (true/false), so you can do like this

if (mail('myemail.co.uk', $email, $message)) {
    echo "Thank you. We will be in touch soon.";
} else {
    echo "Something went wrong, the email was not sent!";
}

另外,邮件的结构(参数)是to-address,subject,message。这意味着您当前的主题是电子邮件地址,我不知道这是否是您的意图?

Also, the structure of mail (the parameters) are to-address, subject, message. Which means that your current subject is the email-address, I'm not sure if this is what you intended?

这篇关于PHP表单消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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