简体   繁体   English

使用PHP中的邮件功能不发送电子邮件

[英]No e-mail is send using mail function in PHP

I just need that when form is submitted mail is send to recipient. 我只需要在提交表单时将邮件发送给收件人即可。 My form submitted with Response code of 200k but mail is not Delivered. 我的表单提交的响应代码为200k,但邮件未送达。 I have installed sendmail. 我已经安装了sendmail。

sendmail.php code: sendmail.php代码:

if(isset($_POST['submit']))
{
    $subject = $_POST['subject'];
    $to = "abc@gmail.com";
    $from = $_POST['email'];
     //data
    $msg = "NAME: "  .$_POST['name']    ."<br>\n";
    $msg .= "EMAIL: "  .$_POST['email']    ."<br>\n";
    $msg .= "WEBSITE: "  .$_POST['web']    ."<br>\n";
    $msg .= "COMMENTS: "  .$_POST['comments']    ."<br>\n";
    //Headers
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=UTF-8\r\n";
    $headers .= "From: <".$from. ">" ;
    mail ($to, $subject,$msg, $headers);
    echo "sent";
}

installed mail server in php.ini file: 在php.ini文件中安装了邮件服务器:

 [mail function]
; Setup for Linux systems
 sendmail_path = /usr/sbin/sendmail -t
sendmail_from = me@myserver.com 
mail ($to, $subject,$msg, $headers);
echo "sent";

instead of this ,first check if the mail is sent 代替此,首先检查是否已发送邮件

$mail=mail ($to, $subject,$msg, $headers);
if($mail){
  echo "sent";
}else{
  echo "failed."; 
}

By this actually u can know whether your mail function in working or not 通过这个,您实际上可以知道您的邮件是否正常工作

if it is not working.the problem can be with SMTP settings in your localhost 如果它不起作用,则问题可能出在您本地主机中的SMTP设置上

enable errors in php if not enabled using 如果未启用,则启用php中的错误

ini_set('display_errors',1);

Have you checked mail settings in you php.ini ? 您是否在php.ini中检查了邮件设置?

PHP Runtime Configuration PHP运行时配置

If you don't have access to the PHP settings you can use PHP Mailer to deliver emails with your own parameters 如果您无权访问PHP设置,则可以使用PHP Mailer传递带有自己参数的电子邮件

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

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