简体   繁体   English

简单的联系表将不起作用-PHP

[英]Simple contact form won't work - php

Again - I've looked and troubleshooted for about an hour and cannot get the php contact form to work. 再次-我已经查找并进行了约一个小时的故障排除,无法使php联系人表单正常工作。 I get the "Thank you!" 我得到了“谢谢!” email, but I haven't received the email to my inbox ever. 电子邮件,但我从未收到过发送到我的收件箱的电子邮件。 I've done it about 20 times. 我已经做了大约20次。

<div class="container">
<div class="row">
    <div class="col-lg-12">
      <h5>Want to contact me quickly? Use this form!</h5>
      <form id="contact" method="post" action="submit.php" class="form" role="form">
      <div class="row">
        <div class="form-group col-lg-4">
          <label>Name</label></br>
          <input type="text" name="name" placeholder="Enter your full name" required autofocus>
        </div>
        <div class="form-group col-lg-4">
          <label>Email address</label></br>
          <input type="email" name="email" placeholder="Enter your email address" required autofocus>
        </div>
        <div class="form-group col-lg-4">
          <label>Subject</label></br>
          <input type="text" name="subject" placeholder="Subject">
        </div>
        <div class="form-group col-lg-12">
          <label>Message</label>
          <textarea name="comments" name="message" data-provide="markdown-editable" rows="6" placeholder="Let's chat!" style="width:100%"></textarea>
        </div>
        <div class="form-group col-lg-12 form-action">
          <input type="hidden" name="Submit" value="contact">
          <button type="submit" class="btn btn-default">Submit</button>          
        </div>
    </form>
    </div>
</div>

PHP: PHP:

<?php
if ($_POST['Submit'])
{
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$comments=$_POST['comments'];
$to='MY EMAIL ADDRESS';
$from='website';

if (mail($to, $subject, $name, $email, $comments))
{
    echo 'Thank you!';
}
else
{
    echo 'Something went wrong! Try again';
}
}?>

Any help is greatly appreciated. 任何帮助是极大的赞赏。 I have my MAMP server on and I get the "thank you!" 我已经安装了MAMP服务器,并且得到“谢谢!” message every time, but I haven't gotten any emails. 每次都发信息,但我没有收到任何电子邮件。 Also, I'd really like it to show the "thank you!" 另外,我真的很想显示“谢谢!” and then return to my webpage, but I can't even get the php to work so I maybe should hold off on that part. 然后返回到我的网页,但是我什至无法使php正常工作,所以我也许应该坚持一下。

You have a wrong call of mail() function. 您错误地调用了mail()函数。 It should be like this: 应该是这样的:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

So, for your case: 因此,对于您的情况:

<?php
if ($_POST['Submit'])
{
    $name=$_POST['name'];
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $comments=$_POST['comments'];
    $to='email@email.com';
    $from='website';

    $message = 'Message: ' . $comments . "\r\n";
    $message .= 'From: ' . $from;

    $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";

    if (mail($to, $subject, $message, $headers))
    {
        echo 'Thank you!';
    }
    else
    {
        echo 'Something went wrong! Try again';
    }
}
?>

The mail() function simply returns true if the message has been queued without error in your system... but it doesn't tell you whether the email was actually sent or not. 如果邮件已在系统中排队且没有错误,则mail()函数仅返回true,但是它不会告诉您电子邮件是否实际上已发送。 I see you're using Mac OS X, so you'll have to configure SMTP settings (provided by your ISP) in the PHP environment to get mail sending working. 我看到您使用的是Mac OS X,因此必须在PHP环境中配置SMTP设置(由ISP提供)才能使邮件发送正常。

Alternately, you can use a service like Amazon SES to send emails through PHP. 或者,您可以使用Amazon SES之类的服务通过PHP发送电子邮件。

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

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