2014-11-08 125 views
0

我已经配置我的php.ini和sendmail设置为其他人的指示,但我仍然无法通过使用PHP中的mail()函数从本地主机发送任何邮件。PHP本地主机邮件没有得到使用xampp发送

这些都是我的php.ini [邮件功能]设置

[mail function] 
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury 
; SMTP = localhost 
; smtp_port = 25 



sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 


;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe" 


and this is my sendmail.ini settings 

smtp_server=smtp.gmail.com 


; smtp port (normally 25) 

smtp_port=587 



smtp_ssl=tls 


error_logfile=error.log 

auth_username= [email protected] 
auth_password= examplepassword 

我的操作系统是Windows 8。我是新来的PHP或任何服务器端编程。

这将是非常有益的,如果大家能帮助我,也许发送正确的设置等。感谢球员:d :)

回答

1

您可以使用phpMailer,更容易和完美的作品。

你需要下载这两个文件并把它们放在同一个目录下:

http://goo.gl/TyYgty

那么你需要要求/包括class.phpmailer.php

// change the path of the file 
require_once("_path_to/class.phpmailer.php"); 

一旦做了你需要配置phpMailer()功能设置:

注意:您需要提供一个有效的电子邮件,方法是转到您的域名c面板并创建一封带密码的电子邮件,然后将其添加到下面的配置中,或者您可以使用Gmail作为host,email,password而不是如果您没有主机或域名,则发送电子邮件,但在这种情况下,$mail->Port将是Gmail端口,也可能是465,而$mail->SMTPSecure将是ssl

$mail = new PHPMailer(); 
     $mail->IsSMTP(); 
     $mail->SMTPDebug = 1; 
     $mail->SMTPAuth = true; 
     $mail->SMTPSecure = "http"; 
     $mail->Host = "your webmail host domain"; // ex. [email protected] 
     $mail->Port = 25; 
     $mail->Username = "sender email goes here"; // ex. [email protected] 
     $mail->Password = "sender email password goes here"; 
     $webmaster_email = "sender email goes here"; // ex. [email protected] 
     $mail->From = $webmaster_email; 
     $mail->FromName = "sender name goes here"; // ex. John Doe 
     $mail->AddAddress($email); 
     $mail->AddReplyTo($webmaster_email); 
     $mail->IsHTML(true); 
     $mail->Subject = "your message subject goes here"; 
     $mail->Body = 'your message body goes here'; // take a look on google, how to send html email body 

     if(!$mail->Send()) 
     { 
      echo 'An error occurred, Please try again later'; 
     }else { 
      echo 'Email Sent!'; 
     } 

然后你就可以在任何地方使用它,随时随地localhost/webserver

相关问题