Phpmailer无法从localhost(XAMPP)运行

时间:2015-02-01 07:50:38

标签: xampp phpmailer

我使用在localhost上运行的phpmailer从发送邮件功能中受到困扰。

我使用XAMPP, phpmailer

$mail->IsSMTP()$mail->IsSendmail()在托管方面运行良好,但不是本地主机。

我曾尝试过互联网上提到的许多解决方案,例如启用了OPENSSL (extension=php_openssl.dll)

For using $mail->IsSendmail() of phpmailer, it shown "Could not execute: /usr/sbin/sendmail".

For using $mail->IsSMTP() with well configured, all are setting correctly.

显示

 "SMTP Error: Could not authenticate.", 

我从调试器获得了信息,有信息"...SMTP -> ERROR: Password not accepted from server:..."

但是那些在实时托管环境中没有问题,只是不能在localhost上工作。

希望有人能给我一些想法。非常感谢。

2 个答案:

答案 0 :(得分:1)

isSendmail不太可能在Windows上运行 - 如果您安装了本地邮件服务器,请使用isMail,如果安装了本地邮件服务器,请确保它已启动并运行(例如telnet localhost 25)。 isSMTP直接发送,不受本地邮件配置的影响,这就是为什么它适合您。你还应该read the troubleshooting docs

答案 1 :(得分:-2)

下载&安装PHPMailer

  

https://github.com/PHPMailer/PHPMailer   提取 class.phpmailer.php class.smtp.php   取消注释位于 xampp / php / 文件夹下的 php.ini 中的; extension = php_openssl.dll   找到 [邮件功能] 并更改(对于Microsoft)

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

编辑 class.smtp.php ,主机和端口参数如(适用于Linux): $ host =“ssl://smtp.gmail.com”$ port = 465

[edit delete sendmail params]

发送邮件的示例代码:

   <?php
require_once "phpmailer/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourusername@gmail.com"; // Enter your SMTP username
$mail->Password = "yourpassword“; // SMTP password
$webmaster_email = "yourusername@yourdoamin.com"; //Add reply-to email address
$email="yourusername@domain.com"; // Add recipients email address
$name="name"; // Add Your Recipient’s name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = <strong>50</strong>; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML

$mail->Subject = "This is your subject";

$mail->Body =      "Hi, this is your email body, etc, etc" ;      //HTML Body

$mail->AltBody = "Hi, this is your email body, etc, etc";     //Plain Text Body
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>