简体   繁体   English

lampp中的mail()不起作用

[英]mail() in lampp doesn't work

I'm trting to send a simple mail script in PHP. 我想用PHP发送一个简单的邮件脚本。 It doesn't work and I have no error in mail log or error log. 它不起作用,我在邮件日志或错误日志中没有错误。

Here's my php.ini config 这是我的php.ini配置

SMTP = relais.videotron.ca
smtp_port = 25
sendmail_from = xxxx@xxxx.com (Of cours it's my ISP email there :D)
sendmail_path = /usr/sbin/sendmail -i -t

and my simple mail() test 和我简单的mail()测试

mail("xxxx@xxxx.com","test","test");

Nothing's work. 没什么可行的。 What could it be? 会是什么呢?

The built-in PHP mail command doesn't allow you to authenticate to an SMTP server. 内置的PHP mail命令不允许您对SMTP服务器进行身份验证。 Your ISP SMTP server requires authentication and so is refusing the connection. 您的ISP SMTP服务器需要身份验证,因此拒绝连接。

The info provided by your ISP confirms this; 您的ISP提供信息确认了这一点;

SMTP server is accessible from an external network by using clear text authentication using your code "VL" or alias for your mail Example: customer@videotron.ca 可以使用代码“VL”或邮件别名使用明文身份验证从外部网络访问SMTP服务器示例:customer@videotron.ca

Your options are either use an SMTP server that allows anonymous connections or (as Eamorr says) use a mailer class. 您的选择是使用允许匿名连接的SMTP服务器,或者(如Eamorr所说)使用邮件程序类。

I use SwiftMailer: 我使用SwiftMailer:

require_once('../lib/swiftMailer/lib/swift_required.php');
...
function sendEmail(){
  //Sendmail
  $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

  //Create the Mailer using your created Transport
  $mailer = Swift_Mailer::newInstance($transport);

  $body="Dear $fname,\n\nYour job application was successful. \n\nYours,\n\nEamorr\n\n\n\n\n\n\n";


  //Create a message
  $message = Swift_Message::newInstance('Subject goes here')
    ->setFrom(array($email => "no-reply@yourdomain.com"))
    ->setTo(array($email => "$fname $lname"))
    ->setBody($body);

  //Send the message
  $result = $mailer->send($message);
}

You can send both plaintext and html email with ease. 您可以轻松发送纯文本和HTML电子邮件。

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

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