Php mail()函数不起作用-如何解决?

Php mail()函数不起作用-如何解决?,php,email,phpmailer,Php,Email,Phpmailer,mail()函数在我的服务器上不起作用。我使用了basic mail()代码来了解脚本是否有问题。但它仍然没有发送电子邮件。有人建议我更改服务器上的设置以启用mail()函数或类似的功能 我该怎么做?我如何知道我的服务器允许mail()或它正确运行mail() 有什么建议吗 如果您首先使用共享服务器,我建议您与他们联系,如果他们对此负责。如果它发送电子邮件之前,它可能是你的原因,你可能需要改变你的代码。 您没有提供任何示例代码,但这是我的示例代码,请尝试: $to= "$confoema

mail()函数在我的服务器上不起作用。我使用了basic mail()代码来了解脚本是否有问题。但它仍然没有发送电子邮件。有人建议我更改服务器上的设置以启用mail()函数或类似的功能

我该怎么做?我如何知道我的服务器允许mail()或它正确运行mail()


有什么建议吗

如果您首先使用共享服务器,我建议您与他们联系,如果他们对此负责。如果它发送电子邮件之前,它可能是你的原因,你可能需要改变你的代码。 您没有提供任何示例代码,但这是我的示例代码,请尝试:

    $to= "$confoemail";
    $subject="Your Contact Request at somewebsite.Com";
    $message= "the message to send";
    $headers  = 'MIME-Version: 1.0' . "\r\n".
     'Content-type: text/html; charset=iso-8859-1' . "\r\n".
     'From: justin@webmasteroutlet.com' . "\r\n" . //that code here //perfectly works, search if the code is built -in of php.
   'Reply-To: justin@webmasteroutlet.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
    mail($to,$subject, $message, $headers);  

你在运行什么操作系统

在ubuntu上,您可以尝试安装邮件服务器(postfix或sendmail)


如果使用
phpmailer
库,则不能使用
mail()。因为它有预定义的功能。你可以通过访问来检查

PhpMailer使用
$mail->Send()
而不是
mail()

PhpMailer的示例代码

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

在你的主机上测试这个,如果它不工作,你的主机已禁用邮件。大多数免费服务都会屏蔽哪些内容。给我发个短信,免费为你的测试提供一个小型主机

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];;
$subject = $_POST['subject'];
$message = $_POST['message'];
$name = "somename"; $email="test@test.com"; $phone="1111111111" $subject="test"; $message="the message";

$to      = 'info@fullertoncomputerepairwebdesign.com';
$subject = 'Message From Website';
$headers = 'From: info@fullertoncomputerepairwebdesign.com' . "\r\n" .
    'Reply-To: info@fullertoncomputerepairwebdesign.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$themessage = "Name: ".$name."</br>Email: ".$email."</br>Phone: ".
                $phone."</br>Subject: ".$subject.
                "</br>Message: ".$message;
//echo $themessage;
mail($to, $subject, $themessage, $headers);
$name=$\u POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];;
$subject=$_POST['subject'];
$message=$_POST['message'];
$name=“somename”$电子邮件=”test@test.com"; $phone=“1111111”$subject=“test”$message=“消息”;
$to$info@fullertoncomputerepairwebdesign.com';
$subject='来自网站的消息';
$headers='来自:info@fullertoncomputerepairwebdesign.com' . “\r\n”。
答复:info@fullertoncomputerepairwebdesign.com' . “\r\n”。
“X-Mailer:PHP/”。phpversion();
$themessage=“Name:”.$Name。”
电子邮件:“.$Email。”
电话:”。 $phone.“
主题:”.$Subject。 “
消息:”.$Message; //echo$themessage; 邮件($to、$subject、$themessage、$headers);
你检查过你的垃圾邮件文件夹吗?你能发布你的代码吗?@SaifudheenMak很乐意帮忙:)
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];;
$subject = $_POST['subject'];
$message = $_POST['message'];
$name = "somename"; $email="test@test.com"; $phone="1111111111" $subject="test"; $message="the message";

$to      = 'info@fullertoncomputerepairwebdesign.com';
$subject = 'Message From Website';
$headers = 'From: info@fullertoncomputerepairwebdesign.com' . "\r\n" .
    'Reply-To: info@fullertoncomputerepairwebdesign.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$themessage = "Name: ".$name."</br>Email: ".$email."</br>Phone: ".
                $phone."</br>Subject: ".$subject.
                "</br>Message: ".$message;
//echo $themessage;
mail($to, $subject, $themessage, $headers);