如何使用PHP设置电子邮件表单?

如何使用PHP设置电子邮件表单?,php,forms,email,contact-form,mailto,Php,Forms,Email,Contact Form,Mailto,我试图用php创建一个简单的电子邮件表单,但是在对它和所有东西进行样式化之后,它就不起作用了。我想修复我已有的表单,而不是使用其他人编写的难看模板。如何设置此设置,以便管理员电子邮件接收在名称、电子邮件和消息字段中填写的内容的通知。非常感谢您的帮助!以下是html: <form id="contact-form" class="contact-form" action="contact.php"> <p class="contact-name"> <inpu

我试图用php创建一个简单的电子邮件表单,但是在对它和所有东西进行样式化之后,它就不起作用了。我想修复我已有的表单,而不是使用其他人编写的难看模板。如何设置此设置,以便管理员电子邮件接收在名称、电子邮件和消息字段中填写的内容的通知。非常感谢您的帮助!以下是html:

<form id="contact-form" class="contact-form" action="contact.php">
  <p class="contact-name">
  <input id="contact_name" type="text" placeholder="Full Name" value="" name="name" />
  </p>

  <p class="contact-email">
<input id="contact_email" type="text" placeholder="Email Address" value="" name="email" />
  </p>
            <p class="contact-message">
                <textarea id="contact_message" placeholder="Your Message"     name="message" rows="15" cols="40"></textarea>
            </p>
            <p class="contact-submit">
                <a id="contact-submit" class="submit" href="mailto:email@example.com">Send Your Email</a>
            </p>

            <div id="response">

            </div>
        </form>
验证代码,然后

    private function sendEmail(){
    $mail = mail($this->email_admin, $this->subject, $this->message,
         "From: ".$this->name." <".$this->email.">\r\n"
        ."Reply-To: ".$this->email."\r\n"
    ."X-Mailer: PHP/" . phpversion());

    if($mail)
    {
        $this->response_status = 1;
        $this->response_html = '<p>Thank You!</p>';
    }
}


function sendRequest(){
    $this->validateFields();
    if($this->response_status)
    {
        $this->sendEmail();
    }

    $response = array();
    $response['status'] = $this->response_status;   
    $response['html'] = $this->response_html;

    echo json_encode($response);
}
私有函数sendmail(){
$mail=mail($this->email\u admin,$this->subject,$this->message,
来自:“.$this->name”。\r\n”
“回复:”$this->电子邮件。“\r\n”
“X-Mailer:PHP/”.phpversion());
如果($邮件)
{
$this->response\u status=1;
$this->response_html='谢谢!

'; } } 函数sendRequest(){ $this->validateFields(); 如果($this->response\u status) { $this->sendmail(); } $response=array(); $response['status']=$this->response\u status; $response['html']=$this->response\u html; echo json_编码($response); }
尚未测试您的代码,但似乎没有问题,通常情况下,当电子邮件不适用于用户时,是因为他们的计算机上没有安装smtp服务器,正在尝试在本地进行测试,和/或没有在路由器/防火墙上打开正确的端口(我认为是端口25)。尝试代码的一个好方法是在生产环境(如果您有一个实际的主机)上测试它。是的,代码看起来不错。使用以下选项启用错误报告:
ini\u set('display\u startup\u errors',1);ini设置(“显示错误”,1);错误报告(-1)-并查看是否触发任何错误。如果没有,则@aleation是正确的。@rm vanda问题是,对于mail()函数,它通常只返回true或false,如果在没有错误的情况下触发
mail()
函数,它将返回true,但这并不保证它被发送。它刚刚被发送到“服务器”,现在是它的问题了,请不要在互联网上发布邮件地址。有人可能真的拥有这个地址,多亏了你,现在就会被垃圾邮件发送者强奸。使用
example.com
example.org
进行此类用途;例如,这是经批准的URL。
    private function sendEmail(){
    $mail = mail($this->email_admin, $this->subject, $this->message,
         "From: ".$this->name." <".$this->email.">\r\n"
        ."Reply-To: ".$this->email."\r\n"
    ."X-Mailer: PHP/" . phpversion());

    if($mail)
    {
        $this->response_status = 1;
        $this->response_html = '<p>Thank You!</p>';
    }
}


function sendRequest(){
    $this->validateFields();
    if($this->response_status)
    {
        $this->sendEmail();
    }

    $response = array();
    $response['status'] = $this->response_status;   
    $response['html'] = $this->response_html;

    echo json_encode($response);
}