简体   繁体   English

电子邮件联系表格不起作用

[英]email contact form is not working

I was wondering if someone could see what I am doing wrong here. 我想知道是否有人在这里看到我在做什么错。 My html looks like this 我的HTML看起来像这样

<form action="process.php" method="post">
    <fieldset>
        <div id="inputLeft">
            <p>
                <label for="name">Full Name</label>
                <input class="validate[required,custom[onlyLetter],length[0,100]]" name="name" type="text" id="name" value="">
            </p>
            <p>
                <label for="email">Email Address</label>
                <input class="validate[required,custom[email],length[0,100]]" name="email" type="text" id="email" value="">
            </p>
            <p>
                <label for="subject">Subject</label>
                <input class="validate[required,length[5,600]" name="subject" type="text" id="subject" value="">
            </p>
        </div>
        <div id="inputRight">
            <p>
                <label for="country">Country</label>
                <input name="country" type="text" id="country" value="">
            </p>
            <p>
                <label for="phone">Phone Number</label>
                <input name="Phone" type="text" id="phone" value="">
            </p>
            <p>
                <label for="url">Website</label>
                <input name="url" type="text" id="url" value="">
            </p>
        </div>
        <p>
            <label for="message">Message</label>
        <textarea name="message" cols="120" rows="8" id="message"></textarea>
        </p>
    </fieldset>

and the php like this 和这样的PHP

<?php
   # recipient
   $recipient = 'sean@seankonig.co.za'

   # subject
   $subject = $_Post['subject'];

   # headers
   $headers = "Website enquiry <>\r\n";

   # message
   $message =  "Name : {$_POST['name']}\n";
   $message .= "Email : {$_POST['email']}\n";
   $message .= "Subject : {$_POST['subject']}\n";
   $message .= "Message : {$_POST['message']}\n";

   if( mail($recipient, $subject, $message, $headers) ) echo "Mail Sent";
   else echo "Mail Could Not Be Send";
?>

When testing it says that the mail has been sent but nothing delivers. 测试时,它表示邮件已发送,但没有传递。 Could you please have a look and let me know? 你能看一下,让我知道吗?

With a quick look to your code i found a couple of errors that might cause email to not work 快速浏览您的代码后,我发现了一些错误,这些错误可能导致电子邮件无法正常工作

$recipient = 'sean@seankonig.co.za'; //you are missing a semicolon here

$subject = $_Post['subject'];//$_POST is not the same as $_Post

You could also expand your headers . 您还可以扩展headers This doesn't necessarily effect your content, but it can effect whether your mail enters someone spambox or not: 这不一定会影响您的内容,但会影响您的邮件是否进入垃圾邮件箱:

$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= "FROM: Website.com <noreply@website.com>" . PHP_EOL;
$headers .= "Return-Path: noreply@website.com" . PHP_EOL;
$headers .= "Reply-To: noreply@website.com" . PHP_EOL;

Please note that PHP_EOL may also be written as \\r\\n , but for my scripts PHP_EOL works better (headers were shown as content in sent mails). 请注意, PHP_EOL也可以写为\\r\\n ,但是对于我的脚本而言, PHP_EOL效果更好(标头显示为已发送邮件中的内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM