php代码不通过电子邮件发送

php代码不通过电子邮件发送

本文介绍了php代码不通过电子邮件发送给我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的html表单代码

Here is my html form code

我创建了这个,它的工作正常与mailto功能,但问题是它只是客户端,我想要它在服务器端工作,以便从他们提供的电子邮件中发送电子邮件。

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.

<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>

我没有任何问题,直到它来到我的PHP代码。

I haven't had any problems with it until it came to my php code.

这是我的PHP代码

<?php
if(isset($_POST['submit'])){
    $to = "[email protected]"; // 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);
    }
?>

请任何人帮我。

推荐答案

编辑: 我最初建议在From:头后添加一个空格,但现在已经重新读取了RFC本身,似乎空间将成为价值的一部分,所以我删除了这个建议。 From:{$ from}优于From:{$ from}

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:{$from}" is preferable to "From: {$from}".

-

如果您在Windows主机上,则需要在 php.ini 之前,您可以发送电子邮件与 mail()。请参阅。

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(). See mail()#Notes.

如果你在Linux上,你的PHP错误日志文件中应该有错误信息。您可以通过在服务器上的任何位置运行以下代码,然后在输出中搜索 error_log 来查找其位置。

If you're on Linux, you should have an error message in your PHP error log file. 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.

<?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.

这篇关于php代码不通过电子邮件发送给我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:11