简体   繁体   English

PHP代码没有给我发电子邮件

[英]php code isn't emailing me

Here is my html form code 这是我的HTML表单代码

I created this and it worked fine with the mailto function, but the problem with it was that it was client side only, and I want it to work server side, so that it sends me the email from the email that they provide. 我创建了它,并且可以与mailto函数一起很好地工作,但是问题是它仅在客户端,并且我希望它在服务器端工作,以便从他们提供的电子邮件中向我发送电子邮件。

<form action="mailto.php" method="post">
<p>Title:<select>
     <option value="Mr">Mr</option>
     <option value="Mrs">Mrs</option>
     <option value="Miss">Miss</option>
     <option value="Dr">Dr</option>
</select></p>
     <p>First name: <input type="text" name="firstname"></p>
     <p>Last name: <input type="text" name="lastname"></p>
     <p>Steam name: <input type="text" name="steam name"></p>
     <p>Email: <input type="text" name="email"></p>
     <p>What will you bring to this clan? (250 charcater limit)</p>
     <p><textarea name="textbox" id="textbox" textarea maxlength="250"></textarea></p>
     <p><input type="submit" name="submit" value="Submit">
        <input type="reset" value="Reset"></p>
</form>

I haven't had any problems with it until it came to my php code. 直到涉及到我的php代码,我都没有遇到任何问题。

Here is my php code 这是我的PHP代码

<?php 
if(isset($_POST['submit'])){
    $to = "someone@hotmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $subject = "Form submission";
    $message = $firstname . " " . $lastname . " What will you bring to this group?:" . "\n\n" . $_POST['textbox'];

    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    }
?>

please can anyone help me. 请任何人能帮助我。

Edit: I originally suggested adding a space after the From: header, however having now re-read the RFC itself, it seems that the space would become part of the value, so I've removed that advice. 编辑: 我最初建议在From:标头之后添加一个空格,但是现在重新读取RFC本身,似乎该空格将成为值的一部分,因此我删除了该建议。 "From:{$from}" is preferable to "From: {$from}" . "From:{$from}"优于"From: {$from}"

-- -

If you're on a Windows host, you need to provide SMTP connection details in php.ini before you can send e-mails with mail() . 如果您使用的是Windows主机,则需要先在php.ini提供SMTP连接详细信息,然后才能使用mail()发送mail() See mail()#Notes . 请参阅mail()#Notes

If you're on Linux, you should have an error message in your PHP error log file. 如果您使用的是Linux,则PHP错误日志文件中应该包含一条错误消息。 You can find out where this is located by running the following code anywhere on the server and then searching for error_log in the output. 您可以通过在服务器上的任何位置运行以下代码,然后在输出中搜索error_log来找出其位置。

<?php
phpinfo();

Once you know the error that's being generated, I can help more. 一旦您知道所产生的错误,我将为您提供更多帮助。 It may be that the email is being sent successfully and it's being eaten by your spam filter when it reaches the other end. 可能是电子邮件已成功发送,到达另一端时被垃圾邮件过滤器吞噬了。

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

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