我已经购买了主机并创建了网络邮件。但是联系表的邮件功能在我的主机中不起作用。它打印“错误”。我不明白我错在哪里。我已经在谷歌搜索,查看了示例,但我没有解决我的问题。请帮助我。谢谢。 编辑信息:当我进行托管时,它是 Windows 托管。maik 功能正在运行。但是,我通过了 linux 托管,然后在 cpanel 中再次创建了邮件。但是,现在邮件功能不起作用。再次感谢。
Edit2:嗨,这段代码在 Windows 托管中工作。我认为问题源于linux托管......这是我的代码:
联系人.html
<html>
<form action="contact_form.php" method="POST" enctype="multipart/form-data" id="contactform">
<fieldset class="row">
<legend>Contact me :)</legend>
<p>
<label for="your-name">Your Name</label>
<input type="text" name="name" id="your-name" class="input-xlarge">
</p>
<p>
<label for="your-email">Your Email <span class="required">(required)</span></label>
<input type="email" name="email" id="your-email" class="input-xlarge" required>
</p>
<p>
<label for="your-subject">Subject</label>
<input type="text" name="subject" id="your-subject" class="input-xlarge">
</p>
<p>
<label for="your-message">Your message <span class="required">(required)</span></label>
<textarea name="message" cols="50" rows="10" id="your-message" class="input-xxlarge" required placeholder="What do you want to say?"></textarea>
</p>
<!-- This is hidden for normal users -->
<div class="hidden">
<label>
Do not fill out this field
<input name="s_check">
</label>
</div>
<p>
<input type="submit" id="submit" name="submit" class="primary" value="Send Message">
</p>
<p hidden id="response"></p>
</fieldset>
</form>
</html>
联系表格.php
<?php
if(isset($_POST['submit'])) {
$to = 'info@xyz.com';
$name = stripslashes($_POST['name']); //sender's name
$email = stripslashes($_POST['email']); //sender's email
$subject = stripslashes($_POST['subject']); // the subject
echo $name."<br/>";
echo $email."<br/>";
echo $subject."<br/>";
//The message you will receive in your mailbox
$msg = "From : $name \r\n"; //add sender's name to the message
$msg .= "e-Mail : $email \r\n"; //add sender's email to the message
$msg .= "Subject : $subject \r\n\n";
$msg .= "---Message--- \r\n".stripslashes($_POST['message'])."\r\n\n"; $msg .= "---User information--- \r\n"; //Title
$msg .= "User IP : ".$_SERVER["REMOTE_ADDR"]."\r\n"; //Sender's IP
$msg .= "Browser info : ".$_SERVER["HTTP_USER_AGENT"]."\r\n"; //User agent
$msg .= "User come from : ".$_SERVER["HTTP_REFERER"]; //Referrer
if (mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")){
//Message sent!
echo nl2br("
<div class=\"MsgSent\">
<h1>Congratulations!!</h1>
<p>Thank you <b><?=$name;?></b>, your message is sent!<br /> I will get back to you as soon as possible.</p>
</div>
");
exit;
}
else{
// Display error message if the message failed to send
echo "
<div class=\"MsgError\">
<h1>Error!!</h1>
<p>Sorry <b><?=$name;?></b>, your message failed to send. Try later!</p>
</div>";
exit;
}
}
?>