如何在xampp上使用phpmailer发送邮件

问题描述 投票:0回答:2

我一直试图在xampp上使用php邮件发送邮件,我确实收到此错误消息无法发送消息。邮件程序错误:以下发件人地址失败:[email protected]:调用Mail()而未连接

拜托,我需要帮助解决这个问题。这是我的代码;

<?php
require( 'class.phpmailer.php' );

  $mail = new PHPMailer;
  $mail->IsSMTP();
  $mail->SMTPAuth = true;
  $mail->Host = "tls://smtp.gmail.com";
  $mail->Port = 25;
  $mail->Username = "[email protected]";
  $mail->Password = "xxxxx";
  //Sending the actual email
  $mail->setFrom('[email protected]', 'Aaron');
  $mail->addAddress('[email protected]', 'Aaron');     // Add a recipient
  $mail->isHTML(false);                                  // Set email format to HTML
  $mail->Subject = 'Calculation form results from ';
  $mail->Body = 'testing...';

  if(!$mail->send()) {
    echo 'Message could not be sent. ';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit;
  }
?>
php xampp smtp phpmailer sendmail
2个回答
3
投票

直接从https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps复制

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6

//Set the SMTP port number - 587 for authenticated TLS
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "[email protected]";

//Password to use for SMTP authentication
$mail->Password = "yourpassword";

//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'First Last');

//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'First Last');

//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'John Doe');

0
投票

我尝试使用Composer和github,但是无法通过xampp获取最新版本的phpmailer来处理我的测试php电子邮件。当我在localhost上运行程序时,它一直在崩溃,因为电子邮件代码正在寻找php邮件程序类。所以我回到谷歌,忽略了作曲家,并下载了一个简单的普通邮件的PHP邮件5.2.0,并将此zip文件直接提取到我的'websiteX'测试文件夹中,该文件夹位于xampp中的htdocs中。

在我的'website'文件夹中,我有我的测试mail.php文件以及我的phpmailer解压缩文件夹,它包含class.phpmailer,它实际上适用于我的情况。

我花了一个星期的时间,但现在我有xampp php电子邮件完全进入我的测试Gmail帐户。我也使用chrome和notepad ++。

有趣的是我用php mail()命令运行了php电子邮件,虽然Gmail很难反弹,但这并不好。我上周做的第一件事就是让Mercury邮件(包含在xampp中)工作。我按照这个链接https://www.open-emr.org/wiki/index.php/Mercury_Mail_Configuration_in_Windows并设法让xampp与gmail通信,这太棒了!

祝你的编码好运。

© www.soinside.com 2019 - 2024. All rights reserved.