我想知道是否有人能在这里看到我做错了什么。我的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>
和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";
?>
测试时说邮件已经发送但没有发送。你能好好看一下让我知道吗?
答案 0 :(得分:0)
通过快速查看代码,我发现了一些可能导致电子邮件无法正常工作的错误
$recipient = 'sean@seankonig.co.za'; //you are missing a semicolon here
$subject = $_Post['subject'];//$_POST is not the same as $_Post
答案 1 :(得分:0)
您还可以展开headers
。这不一定会影响您的内容,但它会影响您的邮件是否进入某个spambox:
$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;
请注意,PHP_EOL
也可以写为\r\n
,但对于我的脚本PHP_EOL
效果更好(标题在已发送的邮件中显示为内容)。