简体   繁体   English

php电子邮件脚本不发送电子邮件

[英]php email script not sending email

I have a script for sending an email from a form on a website. 我有一个脚本,用于从网站上的表单发送电子邮件。 I know the code is fine - I've previously tested with two different hosting companies. 我知道代码很好 - 我之前已经测试过两个不同的托管公司。 This time I'm using it on a an actual server, as opposed to a hosting company. 这次我在一个实际的服务器上使用它,而不是托管公司。 Basically the user fills in the form, clicks submit and gets the confirmation page that the message has been sent. 基本上用户填写表单,点击提交并获取消息已发送的确认页面。 The only thing is no email comes. 唯一没有电子邮件来。 Here is the script: 这是脚本:

 $nickname = $_REQUEST['nickname'] ;
  $email = $_REQUEST['email'] ;
  $tel = $_REQUEST['tel'] ;
      $comp = $_REQUEST['comp'] ;
  $message = $_REQUEST['message'] ;


// Let's check if all fields are filled in!
if(empty($nickname) || empty($email) || empty($comp))
{
$error = "All of the required fields have not been completed, <a href=\"javascript:history.go(-1)\">please click here to go back.</a>";
}
else
{
$content= "$nickname has sent you an e-mail from XXX
Query:
$message
You can contact $nickname via Email: $email. <br />Other relevant details of individual: <br />Telephone Number: $tel <br />Company: $comp";

mail( "user@gmail.com", "Query", $content, "From: $email"); //first thing has to be address it is going to, then what the subject of the mail should be, the content and a from address which will be the query submitter.
echo  "<h2>$nickname</h2><br></br>
    Your query has been succesfully sent. <br></br><br></br>
    We will deal with this query and be in touch as soon as possible.<br></br><br></br><br></br> 
    The contact details you submitted are: <br></br><br></br>
    <strong>Email:</strong>&nbsp; $email<br></br><br></br>
    <strong>Phone:</strong>&nbsp; $tel<br></br><br></br>
    <strong>Company:</strong>&nbsp; $comp<br></br><br></br>
    <a //href=\"javascript:history.go(-1)\"> Click here to return to the contact page.</a></br>";
}; 

?>

I don't know if this matters either but up until recently, PHP would not work on the server, and gave a HTTP error 405 error saying the verb was not allowed. 我不知道这是否重要但直到最近,PHP无法在服务器上运行,并且发出HTTP错误405错误,说不允许使用动词。 This has since been resolved. 这已经解决了。

Congratulations. 恭喜。 You've created an open SPAM service that allows everyone to send mass-mails. 您已经创建了一个开放的垃圾邮件服务,允许每个人发送群发邮件。

Check this out: 看一下这个:

http://www.securephpwiki.com/index.php/Email_Injection#php_mail.28.29_function http://www.securephpwiki.com/index.php/Email_Injection#php_mail.28.29_function

:-) :-)

The PHP script is not even suppose to send the email, a mail server like sendmail, qmail or postfix does that. PHP脚本甚至不想发送电子邮件,像sendmail,qmail或postfix这样的邮件服务器。 Check if they are configured well. 检查它们是否配置良好。

Most likely your server doesn't have an MTA (mail transfer agent) installed. 很可能您的服务器没有安装MTA(邮件传输代理)。 PHP's mail() function doesn't send the email itself, it passes the result to the system's default MTA. PHP的mail()函数本身不发送电子邮件,它将结果传递给系统的默认MTA。

Quick question - are you using a Windows-based server? 快速提问 - 您使用的是基于Windows的服务器吗? Unix/Linux servers almost always have an MTA in their default setup (usually sendmail or exim or some such), but Windows servers generally don't; Unix / Linux服务器的默认设置几乎总是有一个MTA(通常是sendmail或exim或者其他),但是Windows服务器通常不会; you have to install one yourself. 你必须自己安装一个。

as Elzo already said the mail functionality is dependent on having a mail server set up and configured properly on your server. 正如Elzo已经说过,邮件功能取决于在服务器上正确设置和配置邮件服务器。 Have a look at http://www.php.net/manual/en/book.mail.php for configuration options for setting up mail server access in php. 有关在php中设置邮件服务器访问的配置选项,请查看http://www.php.net/manual/en/book.mail.php

mail() itself is only a wrapper for the underlying functionality. mail()本身只是底层功能的包装器。

If you don't have administrator access the runtime configuration variables can be very useful: 如果您没有管理员访问权限,则运行时配置变量非常有用:

<?php 
ini_set("SMTP","smtp.example.com" ); 
ini_set('sendmail_from', 'user@example.com'); 
?> 

The sendmail_path variable needs to be set in the system configuration file like this: 需要在系统配置文件中设置sendmail_path变量,如下所示:

sendmail_path = /usr/sbin/sendmail -t -i

If you want better error reporting and support for exceptions with informative messages when somethings goes wrong you should take a look at phpmailer http://phpmailer.worxware.com/ 如果你想要更好的错误报告和支持带有信息性消息的异常,当有些事情出错时你应该看一下phpmailer http://phpmailer.worxware.com/

It gives you a fairly nice object oriented interface to sending emails with good and informative error reporting. 它为您提供了一个相当不错的面向对象的界面,用于发送具有良好且信息量大的错

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

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