2014-11-08 89 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

相關問題