【问题标题】:Cannot send mail with PHP [duplicate]无法使用 PHP 发送邮件 [重复]
【发布时间】:2015-10-01 16:28:48
【问题描述】:

我正在尝试使用以下代码使用 PHP 发送一封非常基本的邮件;

if (mail('mymail@gmail.com','Test mail','Testing mail function!'))
{
    echo "Email was sent successfully!";
}
else
{
    echo "Email was not sent!";
}

但是,输出始终是“未发送电子邮件”。我正在使用 Xaamp 在我的机器上本地运行此脚本。

我已经尝试为此研究解决方案,但没有运气。似乎与服务器配置有关。我试图在 php.ini 中修改 sendmail,但它仍然不起作用。

非常感谢您对此的任何帮助。

谢谢。

【问题讨论】:

  • 邮件服务器的响应是什么?我认为mail() 会将错误响应写入 PHP 日志。
  • @AlexTartan 我在 mac osx yosemite 而不是 windows vista 上运行

标签: php apache email xampp osx-yosemite


【解决方案1】:

你需要运行 Mercury 来模拟一个邮件服务器,这是一个 Mercury 教程:http://system66.blogspot.com.es/2010/01/how-to-send-mail-from-localhost-with.html

或者你可以使用 PHPMailer。

【讨论】:

    【解决方案2】:

    XAMPP 中的邮件设置

    $this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
    $this->email->to('target@gmail.com'); //receiver mail
    
    $this->email->subject('testing');
    $this->email->message($message);
    
    $this->email->send(); //sending mail
    Configuration in sendmail.ini
    

    路径c:\xampp\sendmail\sendmail.ini

    配置

    [sendmail]
    
    smtp_server=smtp.gmail.com
    smtp_port=25
    error_logfile=error.log
    debug_logfile=debug.log
    auth_username=myemail@gmail.com
    auth_password=yourgmailpassword
    force_sender=myemail@gmail.com
    in php.ini
    

    路径c:\xampp\xampp\php\php.ini

    [mail function]
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
     sendmail_from = yourmail@gmail.com
    

    【讨论】:

      【解决方案3】:

      试试这个库:

      PHPMailer

      您可以使用 smtp 代替 sendmail。

      【讨论】:

      • 感谢它与 PHPmailer 一起工作得很好
      猜你喜欢
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 2016-05-10
      • 2018-03-26
      • 1970-01-01
      • 2017-01-25
      • 1970-01-01
      • 2014-09-05
      相关资源
      最近更新 更多