2015-08-28 82 views
0

我在使用this tutorial在本地主机xampp中发送邮件时遇到问题。我只是研究了这同一主题在How to configure XAMPP to send mail from localhost?在xampp localhost中发送php邮件不起作用

我已经试过这两个链接,但邮件功能不工作,而不是每次这个邮件功能被存储为XAMPP/mailoutput文件夹中的记事本文件。每当我尝试发送一封邮件时,这些邮件都会作为记事本文件存储在xampp文件夹内的邮件输出文件夹中。

我不知道问题出在哪里。我在xampp中更改了我的php.ini和sendmail.ini文件。

的php.ini如下:

SMTP=smtp.gmail.com 
smtp_port=587 
sendmail_from = [email protected] 
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 
[email protected] 
auth_password=my-gmail-password 
[email protected] 

任何人可以帮助我解决这个问题?

+0

http://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server –

+0

即使这一个不工作....我刚刚尝试 –

回答

1

https://github.com/PHPMailer/PHPMailer下载PHPMailer库。

<?php 
require 'PHPMailer/PHPMailerAutoload.php'; 
  
$mail = new PHPMailer; 
  
$mail->isSMTP(); 
$mail->Host = 'smtp.gmail.com'; 
$mail->SMTPAuth = true; 
$mail->Username = '[email protected]'; 
$mail->Password = '******'; 
$mail->SMTPSecure = 'tls'; 
  
$mail->From = '[email protected]'; 
$mail->FromName = 'Raj Amal'; 
$mail->addAddress('[email protected]', 'ansuman'); 
  
$mail->addReplyTo('[email protected]', 'ansuman'); 
  
$mail->WordWrap = 50; 
$mail->isHTML(true); 
  
$mail->Subject = 'Using PHPMailer'; 
$mail->Body    = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost'; 
  
if(!$mail->send()) { 
   echo 'Message could not be sent.'; 
   echo 'Mailer Error: ' . $mail->ErrorInfo; 
   exit; 
} 

echo'Message has been sent'; Gmail的SMTP主机是smtp.gmail.com。对于Outlook和Yahoo邮件它会有所不同。到地址应该在addAddress()中设置。我认为这对你们真的很有帮助。

+0

我试着用你的解决方案..它显示错误,如:无法发送邮件。邮件错误:SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting –

+0

如果还没有,请尝试以下操作:1.打开xampp-> php-> php.ini 2.搜索扩展名= php_openssl.dll 3.初始将看起来像这样; extension = php_openssl.dll 4.删除';'它会看起来像这个扩展名= php_openssl.dll 5.如果找不到扩展名= php_openssl.dll,请添加这一行extension = php_openssl.dll。 6.然后重新启动你的Xampp。 –

+0

我做了同样的事情你说..即使这不起作用 –