PHP Mailer.单击发送下载php脚本,但不发送邮件 [英] PHP Mailer. Clicking send downloads the php script but does not send mail
问题描述
我正在关注 a教程,介绍如何使用PhP邮件程序脚本实现简单的Bootstrap联系人表单.
I am following a tutorial on how to implement a simple Bootstrap contact form with a PhP mailer script.
但是,当我单击发送消息"时,我的联系表将下载PHP脚本,而不是发送电子邮件.我在做什么错了?
However when I click Send Message, my contact form downloads the PHP script rather than sending the email. What am I doing wrong?
引导程序-HTML
<form name="contactform" method="post" action="http://location_of_my_web_app/php/mailer.php" class="form-horizontal" role="form">
<div class="form-group">
<label for="inputName" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputName" name="inputName" placeholder="Your Name">
</div>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEmail" name="inputEmail" placeholder="Your Email">
</div>
</div>
<div class="form-group">
<label for="inputSubject" class="col-lg-2 control-label">Subject</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputSubject" name="inputSubject" placeholder="Subject Message">
</div>
</div>
<div class="form-group">
<label for="inputPassword1" class="col-lg-2 control-label">Message</label>
<div class="col-lg-10">
<textarea class="form-control" rows="4" id="inputMessage" name="inputMessage" placeholder="Your message..."></textarea>
</div>
</div>
<div class="form-group">
<center>
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-primary">Send Message</button>
</div>
</center>
</div>
</form>
PHP
<?php
/* Set e-mail recipient */
$myemail = "my_address@gmail.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$subject = check_input($_POST['inputSubject'], "Message Subject");
$message = check_input($_POST['inputMessage'], "Your Message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Someone has sent you a message";
$message = "
Someone has sent you a message using your contac form:
Name: $name
Email: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://location_of_my_thank_you_page/Static/contact_thankyou.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
推荐答案
我的联系方式是下载PHP脚本,而不是发送电子邮件"
听起来PHP尚未安装/正在运行或未正确配置.
It sounds like PHP is either not installed/running or not properly configured.
我建议您创建一个名为test.php
的文件,并在其中包含<?php echo "Hello world"; ?>
并查看其是否执行相同的操作.
I suggest that you create a file called test.php
file with <?php echo "Hello world"; ?>
inside it and see if it does the same thing.
如果它仍然想像要下载一样出现,则说明存在问题;未安装PHP或未正确配置PHP,并且无法正常解析PHP.
If it still wants to appear like it wants to download, then there's the problem; PHP is not installed or not properly configured and isn't parsing PHP as it normally should.
创建另一个文件并放置<?php phpinfo(); ?>
,它将显示您服务器的信息.
Create another file and place <?php phpinfo(); ?>
and it should show you the server's information.
这篇关于PHP Mailer.单击发送下载php脚本,但不发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!