我正在使用一个简单的Web表单和一些PHP脚本将完成的表单发送到我的电子邮件中。当我点击“提交”时,我收到PHP文本“谢谢,我们会很快联系”但我没有收到提交表单信息的电子邮件。不确定是什么问题。
来自HTML doc:
<div class='' "letstalk_form">
<form method="get" action="contact.php" name="contact" id="contact">
<p>
<label for="txtfname">Name:</label><input type="text" tabindex="1" name="txtfname" id="txtfname" class="clsTextBox">
</p>
<p>
<label for="txtcompany">Company:</label><input type="text" tabindex="2" name="txtcompany" id="txtcompany" class="clsTextBox">
</p>
<p>
<label for="txtemail">E-mail:</label><input type="text" tabindex="3" name="txtemail" id="txtemail" class="clsTextBox">
</p>
<p>
Message:<textarea name="comments" id="comments" rows="2" cols="20"></textarea>
</p>
<p class="submit">
<input type="submit" value="Submit">
</p>
</form>
</div>
和PHP
$msg = "Sender Name:\t$txtfname\n";
$msg .= "Sender Company:\t$txtcompany\n";
$msg .= "Sender E-mail:\t$txtemail\n";
$msg .= "Comments:\t$comments\n\n";
$recipient = "receiversemail@somewhere.com";
$subject = "from PI Website";
$mailheaders = "From: Lets Do Business <> \n";
$mailheaders .= "Reply-To: $txtemail\n\n";
mail($recipient, $subject, $msg, $mailheaders);
echo "<HTML><HEAD><TITLE>Form Sent!</TITLE></HEAD><BODY>";
echo "<H3 align=center>Thank You, $txtfname</H3>";
echo "<P align=center>Your submission was sent successfully.<br />
I will be contacting you soon.</P>";
echo "</BODY></HTML>";
?>
</div>
我用过这是过去而且效果很好。有没有我忽略的东西?谢谢你的帮助!
编辑:我最终使用Turgut Dursun提供的链接(html-form-guide.com/contact-form/php-email-contact-form.html)来设置表单。效果很好。感谢。
答案 0 :(得分:1)
您是否在代码的这一部分之前将表单中的$ _GET []值分配给变量?
$msg = "Sender Name:\t$txtfname\n";
$msg .= "Sender Company:\t$txtcompany\n";
$msg .= "Sender E-mail:\t$txtemail\n";
$msg .= "Comments:\t$comments\n\n";
$recipient = "abosiger@embarqmail.com";
$subject = "from PI Website";
$mailheaders = "From: Lets Do Business <> \n";
$mailheaders .= "Reply-To: $txtemail\n\n";
mail($recipient, $subject, $msg, $mailheaders);
如果没有,您需要将$ _GET []值初始化为单个变量:
$txtfname = $_GET['textfname'];
通过get发送的每个变量。或者您可以通过以下语法直接从$ _GET数组访问它们:
$msg = "Sender Name:\t" . $_GET['txtfname'] . "\n";
如果有帮助,请告诉我。
答案 1 :(得分:0)
问题可能来自邮件功能的错误配置。你必须正确配置它。
此外,您应该在“发件人”标题中提供一封电子邮件。
答案 2 :(得分:0)
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
像这样改变它。
答案 3 :(得分:0)
如果已发送邮件但未收到任何邮件,则表明您的域存在身份验证问题 ...您的脚本可能工作正常 实现此目的的两种主要方法是使用PHPMail()或SMTP。 PHPMail()已打开,并且已被特洛伊木马和病毒使用。大多数客户端都感染了文件,这些文件仅使用PHPMail()发送邮件,因为它不进行身份验证。它不检查发送的电子邮件是否实际上来自域,这给邮件服务器带来很大压力,使合法邮件在队列中等待很长一段时间。
如果您已经具有使用PHPMail()函数的脚本,将其更改为SMTP非常简单,则只需更改代码的5行,然后在其中添加电子邮件地址和密码(已在cpanel中创建)即可。代码,它将发送电子邮件正常。
if ($_POST['submit']){
$from = "slick@meetslick.com"; //enter your email address
$to = "slickbozz@gmail.com"; //enter the email address of the contact your sending to
$subject = "Contact Form"; // subject of your email
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
$text = ''; // text versions of email.
$html = "<html><body>Name: $name <br> Email: $email <br>Message: $message <br></body></html>"; // html versions of email.
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
//do not ever try to call these lines in reverse order
$body = $mime->get();
$headers = $mime->headers($headers);
$host = "localhost"; // all scripts must use localhost
$username = "support@meetslick.com"; // your email address (same as webmail username)
$password = " here "; // your password (same as webmail password)
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
'username' => $username,'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
// header("Location: http://www.meetslick.com/");
}
}
我希望有一天对某人有帮助。