简体   繁体   English

PHP联系人表格无法正常工作

[英]PHP Contact form won't work

I've tried every php contact form tutorial but I can't get any of them to send the email properly. 我已经尝试了每个php联系人表单教程,但我无法让他们正确发送电子邮件。 They all just show the code but don't send the email. 他们都只显示代码,但不发送电子邮件。 This is the HTML code I have right now: 这是我现在拥有的HTML代码:

<form method="POST" action="scripts/contact.php">
    <input id="name" name="name" placeholder="Name*" type="text" /> <br>
    <input id="subject" name="subject" placeholder="Subject" type="text" /> <br>
    <input id="email_address" name="email" placeholder="Email address*" type="text" /> <br>
    <textarea id="message" name="message" placeholder="Your message*"></textarea>
    <input id="submit" type="submit" name="submit" value="Send" />
</form>

and this is the php I have: 这是我有的PHP:

<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];


$to = "benmuschol@gmail.com";
$subject = "Hello World";
$message = "Name: $name \n Subject: $subject \n Email: $email \n Message: $message \n";
$headers = "From: $email" . $email;
mail($name,$email,$subject,$message,$headers);
echo "Mail Sent.";
?>

I have decent knowledge of HTMl but next to none of PHP. 我对HTMl有一定的了解,但是几乎没有PHP。 Any help would be greatly appreciated. 任何帮助将不胜感激。

first you be sure that php file is exist in path scripts/contact.php 首先,请确保路径脚本/contact.php中存在php文件

second look at phpinfo or php.ini for find is smptp server was setting or not 第二次查看phpinfo或php.ini以查找​​是否设置了smptp服务器

use following php code: 使用以下php代码:

<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];


$to = "benmuschol@gmail.com";
$subject = "Hello World";
$message = "Name: $name \n Subject: $subject \n Email: $email \n Message: $message \n";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: '.$email. "\r\n";


if(mail($to, $subject, $message, $headers))
{
    echo "Mail Sent Successfully.";
}
else
{
    echo "Error in Mail Sent.";
}


?>

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

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