从PHP发送电子邮件中的问题

从PHP发送电子邮件中的问题,php,html,Php,Html,我有这张表格,我正试图将“联系我们”表格的内容发送到此邮件scientology2016@gmail.com但由于某种原因,它没有发送任何邮件,我无法找出其中的错误 <form method="post" action="process.php"> <div class="col-md-6"> <div class="form-group"> <input type="text" class="form-control input-lg" name=

我有这张表格,我正试图将“联系我们”表格的内容发送到此邮件
scientology2016@gmail.com
但由于某种原因,它没有发送任何邮件,我无法找出其中的错误

<form  method="post"  action="process.php">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control input-lg" name="name" placeholder="UserName">
</div>
<div class="form-group">
<input type="text" class="form-control input-lg" name="email" placeholder="E-Mail">
</div>
<div class="form-group">
<input type="text" class="form-control input-lg" name="usertel" placeholder="phone">
</div>
</div>
<div class="col-md-6">
<textarea class="form-control input-lg"  name="subject" placeholder="Your Message"></textarea>

<button type="button" class="btn btn-primary btn-lg btn-block">Contact Us </button>
</div>
</form>

联系我们
这是我写的用于发送邮件的php代码,但它不起作用

<?php
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$subject2 = ($_GET['subject']) ?$_GET['subject'] : $_POST['subject'];
$tel = ($_GET['usertel']) ?$_GET['usertel'] : $_POST['usertel'];
$comment = ($_GET['body']) ?$_GET['body'] : $_POST['body'];

if ($_POST) $post=1;
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.'; 
if (!$comment) $errors[count($errors)] = 'Please enter your comment.'; 
if (!$errors) {
    $to = 'scientology2016@gmail.com';
    $from = $name . ' <' . $email . '>';
    $subject = 'Message from ' . $name; 
    $message = '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
    <table>
        <tr><td>Name</td><td>' . $name . '</td></tr>
        <tr><td>Subject</td><td>' . $subject2 . '</td></tr>
        <tr><td>TelPhone</td><td>' . $tel . '</td></tr>
        <tr><td>Email</td><td>' . $email . '</td></tr>
        <tr><td>Message</td><td>' . nl2br($comment) . '</td></tr>
    </table>
    </body>
    </html>';

    $result = sendmail($to, $subject, $message, $from);
    if ($_POST) {
        if ($result) echo 'Thank you! We have received your message.';
        else echo 'Sorry, unexpected error. Please try again later';
    } else {
        echo $result;   
    }

} else {

    for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
    echo '<a href="form.php">Back</a>';
    exit;
}
function sendmail($to, $subject, $message, $from) {
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";

    $result = mail($to,$subject,$message,$headers);
    if ($result) return 1;
    else return 0;
}
?>


如果您使用的是wamp服务器,有人能帮我吗

首先

在php文件夹中打开php.ini文件并写入或更新

smtp_server=smtp.gmail.com

; smtp port (usually 25)

smtp_port=465

auth_username=scientology2016@gmail.com
auth_password=[MYPASSWORDHERE]

如果您使用的是wamp服务器

首先

在php文件夹中打开php.ini文件并写入或更新

smtp_server=smtp.gmail.com

; smtp port (usually 25)

smtp_port=465

auth_username=scientology2016@gmail.com
auth_password=[MYPASSWORDHERE]

关于PHP邮件的主题已经很多了,但是,
$errors[count($errors)]
可以替换为
$errors[]
。更简单的语法。你得到了什么错误?我没有得到错误,但当我按下按钮时,什么都没有发生,页面保持不变,没有发送电子邮件。关于PHP邮件,已经有很多相关主题,但是,
$errors[count($errors)]
可以替换为
$errors[]
。更简单的语法。你得到了什么错误?我没有得到一个错误,但当我按下按钮时,什么都没有发生,页面保持不变,没有发送电子邮件。我写电子邮件的密码而不是我的密码在这里或什么密码?我写电子邮件的密码而不是我的密码在这里或什么密码?