'mail():" sendmail_from"未在php.ini或自定义“发件人:”中设置标头丢失”错误

时间:2019-12-12 06:14:06

标签: php mysql email

我正在尝试使用Xampp服务器从本地主机发送邮件。我按照下面的php.ini文件更改了php.ini和sendmail.ini文件

php.ini

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = myGmailId@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=myGmailId@gmail.com
auth_password=my-Gmail-Password
force_sender=myGmailId@gmail.com(optional)

mail.php

function db_forgot_password($args){

  $to = $args['email'];  
  $query = "SELECT id FROM tbl_contact WHERE contact = '$to'";
  $result = db_execute($query);
  $contact_id = $result['0']['id'];

  $query = "SELECT user FROM tbl_user_contact WHERE contact = '$contact_id'";
  $result = db_execute($query);
  $user_id = $result['0']['user'];

  if(isset($user_id)){

  $password = 'test123';
  $subject = "Your Recovered Password";

  $query = "SELECT id FROM tbl_login WHERE user = '$user_id'";
  $result = db_execute($query);
  $login_id = $result['0']['id'];

  $query = "UPDATE tbl_login_para SET val = sha1('$password') where para = 1 AND login = '$login_id'";
  $result = db_execute($query);

  $message = "Please use this password to login " . $password;

  if (mail($to,$subject,$message,"From : my@gmail.com")) {
    echo "Email successfully sent to $to_email...";
  } else {
    echo "Email sending failed...";
  }

  succ_return($args);
  }else{
    warn(__FILE__, __FUNCTION__, __LINE__, 'email doesn\'t exist');
    fail_return(ERR_UNAVAILABLE_USERS);
  }
}

执行此API时,它会给我

  

<b>Warning</b>: mail(): &quot;sendmail_from&quot; not set in php.ini or custom &quot;From:&quot; header missing

我该如何解决? 预先感谢

1 个答案:

答案 0 :(得分:0)

从xampp服务器发送电子邮件时,您需要添加有效的电子邮件地址