PHP mail() SMTP 服务器响应:452 4.3.1 Windows 服务器上内存不足


PHP mail() SMTP server response: 452 4.3.1 Out of memory on Windows server

我正在尝试在共享服务器上发送邮件。 我的错误页面是

 <br />
<b>Warning</b>:  mail() [<a href='function.mail'>function.mail</a>]: SMTP server response: 452 4.3.1 Out of memory in <b>D:'hshome'......'form.php</b> on line <b>21</b><br />
email didnt send
<META HTTP-EQUIV ="Refresh" CONTENT =" 1; URL= Thank.html" /> 

这是形式.php

<?php 
include ("config.php");   
$mail_check=true; 
if(trim($_POST["name"])=="") 
    $mail_check=false; 
if(trim($_POST["email"])=="") 
    $mail_check=false; 
if(trim($_POST["subject"])=="") 
    $mail_check=false; 
if($mail_check){ 
    $to=$config["email"]; 
    $subject = $_POST["subject"]; 
    $message = '<html><head><title>$lang["newemailarriveed"]</title></head><body> 
    test
    </body></html>'; 
    $headers  = 'MIME-Version: 1.0' . "'r'n"; 
    $headers .= 'Content-type: text/html; charset=utf-8' . "'r'n"; 
    $headers .= 'From: '.$_POST["name"].' <'.$_POST["email"].'>' . "'r'n"; 
    if(mail($to, $subject, $message, $headers)){ 
        echo $lang["success"]; 
    } 
    else{ 
        echo $lang["eror1"]; 
    } 
}else{ 
    echo $lang["eror2"]; 
} 
?>

config.php

<?php 
// ServCombina
// Contact Form By TalGarty 
    $config = Array( 
        "email" => "info@example.com", 
        );         
    $lang = Array( 
        "newemailarriveed" => "new mail", 
        "newemailfrom" => "from", 
        "info" => "detail", 
        "fullname" => "name", 
        "iemail" => "email", 
        "phone" => "phone", 
        "success" => "success", 
        "eror1" => "email didnt send", 
        "eror2" => "one or more of the fields are empty", 
        );         
?> 

*这是在Windows共享服务器上

不得不说我不太懂 php,我试图通过 asp.net 发送电子邮件并且它奏效了,但是我不能移动到 asp.net m,我必须留在php.

asp.net,以下代码有效:

String s_name = "", s_email = "", s_phone = "";
if (name != null && name.Text != null) { s_name = name.Text; }    
if (email != null && email.Text != null) { s_email = email.Text; }
if (phone != null && phone.Text != null) { s_phone = phone.Text; }
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("example@example.com");
mailMessage.From = new MailAddress("info@example.com");
mailMessage.Subject = "test";
mailMessage.Body = @"<!DOCTYPE html> "+
                    "<html  xmlns='"http://www.w3.org/1999/xhtml'"><head><title>new email</title></head><body> " +
                    "test" +
                    "</body></html>"; 
SmtpClient smtpClient = new SmtpClient("mail.example.com");
smtpClient.Send(mailMessage);
Response.Redirect("~/aaa/Thank.html");

解决方案:

在文件顶部添加以下行:

   ini_set('SMTP','mail.example.com');
   ini_set('sendmail_from','info@example.com');

ini_set('memory_limit','32M');没有帮助,所以我没有把它放在文件中

只需编辑您的 php.ini并将memory_limit更改为您需要的任何内容。例如。memory_limit = 32M

  • 您将需要访问权限才能在系统上对 php.ini 进行更改。此更改是全局的,将由系统上运行的所有 php 脚本使用。更改此值后,需要重新启动 Web 服务器才能使其处于活动状态。请记住,这个限制有其逻辑,不要人为地增加它,因为编写不佳的 php 脚本可能会在没有适当限制的情况下过度杀死您的系统。注意:如果您知道自己在做什么并希望删除内存限制,则应将此值设置为 -1。

  • 使用单个文件夹/虚拟主机的 .htaccess 更改memory_limit更改全局memory_limit可能不是一个好主意,最好仅在需要更改此值以实现其功能的一个文件夹(通常是一个应用程序或虚拟主机(中更改此值。为此,您必须将以下内容添加到相应的位置.htaccess:php_value memory_limit 64M

编辑

如果您的服务器是共享的,则有一种方法可以在脚本中增加允许PHP的内存量。在您的文件顶部放置以下代码。

ini_set('memory_limit','32M');

上面的代码会将 PHP 可用的最大内存量增加到 32 MB。同样,仅针对正在运行的脚本调整设置。