2015-10-15 33 views
0

我已經在我的ubuntu上安裝了postfix,並且在按下按鈕時(我需要從本地服務器發送它)寫下了以下代碼以從本地服務器發送電子郵件:從本地服務器發送一封包含PHP的電子郵件

<!DOCTYPE html> 
<html> 
<form action="email.php" method="post"> 
<input value="Send Email" name="email" type="submit"> 
</form> 
<?php 
if (isset($_POST['email'])) { 
$msg = 'Hello, this is an email from GUI '; 
mail('[email protected]','Sample',$msg); } 
?>     
</html> 

它工作完全正常的Gmail,我收到一封電子郵件,當我按下按鈕。但是,當我將電子郵件地址更改爲我的Thunderbird郵件(工作郵件)時,我什麼也收不到。 這是我在mail.log得到:

後綴/ QMGR [1304]:3C93B1E1B47:去除

但是,當我將其發送到Gmail中我得到我的mail.log發送

+0

您檢查您的垃圾郵件文件夾?錯誤日誌? –

+0

從您的本地服務器?郵件功能不會在本地工作 –

+0

@Jay,日誌中沒有錯誤 – Jack

回答

3

您需要使用php mailer以便它可以工作

您必須擁有有權限的電子郵件地址。就像你HV託管電子郵件...

下載PHPMailer的,你的代碼中添加它,這樣你可以發送郵件.. 這裏是用來通過我的一些rference代碼...

<?php 

require("PHPMailer/class.phpmailer.php"); 
require("PHPMailer/PHPMailerAutoload.php"); 

define("MAILHOST",'hostsite '); 
define("MAILSMTPAuth",true); 
define("MAILUsername",'hosting mail'); 
define("MAILPassword",'password'); 
define("MAILSMTPSecure",'ssl'); 
define("MAILPort",portno); 
define("MAILFrom",'hosting mail'); 
    $mail = new phpmailer(); 
    $result = array(); 

    $mail->isSMTP();          // Set mailer to use SMTP 
    $mail->Host = MAILHOST; // Specify main and backup SMTP servers 
    $mail->SMTPAuth = MAILSMTPAuth;        // Enable SMTP authentication 
    $mail->Username = MAILUsername;     // SMTP username 
    $mail->Password = MAILPassword;       // SMTP password 
    $mail->SMTPSecure = MAILSMTPSecure;       // Enable TLS encryption, `ssl` also accepted 
    $mail->Port = MAILPort;         // TCP port to connect to 

    $mail->From = MAILUsername; 
    $mail->FromName = 'Name'; 
    $mail->isHTML(true); // Set email format to HTML 

    $mail->Subject = " Inquiry Form"; 

    $mail->Body = "message";   


    $mail->SetFrom('hosting mail address', 'name'); 
    $mail->addAddress('recieving mail address', 'Name');  // Add a recipient admin 


     } 
    exit; 
    ?> 
+0

謝謝。我需要一個按鈕,所以當我按下它的電子郵件發送。在我的代碼中,如果部分使用郵件功能,它將如何處理您的代碼? – Jack

+0

我有下載的PHP郵件,但不知道你的程序的細節。你能否詳細說明一下。我無法讓它工作。 – Jack

+0

你是否託管郵件? –

0

嘗試phpmailer,看看它是否適合你。

你可以得到的PHPMailer這裏:https://www.apachefriends.org/download.html

的文件夾添加到您的工作目錄,並在代碼中設置的路徑。

這是我工作的代碼

<?php 
    error_reporting(E_ALL); 
    require("PHPMailer/class.phpmailer.php"); //path of phpmailer 
    $mail = new PHPMailer(); 
    $mail->IsSMTP(); // set mailer to use SMTP 
    $mail->SMTPDebug = 2; 
    $mail->From = "[email protected]"; 
    $mail->FromName = "Gori"; 
    $mail->Host = "smtp.gmail.com"; // specif smtp server 
    $mail->SMTPSecure= "ssl"; // Used instead of TLS when only POP mail is selected 
    $mail->Port = 465; // Used instead of 587 when only POP mail is selected 
    $mail->SMTPAuth = true; 
    $mail->Username = "[email protected]"; // SMTP username 
    $mail->Password = "mypw"; // SMTP password 
    $mail->AddAddress("[email protected]", "Henry"); //replace myname and mypassword to yours 
    $mail->AddReplyTo("[email protected]", "Gori"); 
    $mail->WordWrap = 50; // set word wrap 
    //$mail->AddAttachment("c:\\temp\\js-bak.sql"); // add attachments 
    //$mail->AddAttachment("c:/temp/11-10-00.zip"); 

    $mail->IsHTML(true); // set email format to HTML 
    $mail->Subject = 'test'; 
    $mail->Body = 'test'; 

    if($mail->Send()) {echo "Send mail successfully";} 
    else {echo "Send mail fail";} 
?> 
相關問題