2013-09-26 53 views
-1

我想從我的PHP應用程序發送郵件。以下是我的代碼。郵件沒有被髮送與PHP

<?php 
    error_reporting (E_ALL); 
    ini_set ('SMTP', 'smtp.live.com'); 
    ini_set ('smtp_port', '587'); 
    ini_set ('sendmail_from', '[email protected]'); 

    $to = "[email protected]"; 
    $subject = "Test mail"; 
    $message = "Hello! This is a simple email message."; 

    $headers = "From:[email protected]\r\n"; 
    $headers .= "X-Mailer: php\r\n"; 
    $headers .= "Reply-To:[email protected]\r\n"; 
    $headers .= 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    $result = mail($to,$subject,$message,$headers); 
    if($result) 
    { 
    echo "Mail Sent."; 
    } 
    else 
    { 
    echo ("error"); 
    } 
    ?> 

它給我留言「郵件發送」,所以我希望收到郵件......但不要。假設收到郵件可能會有延遲,我現在等了3天。也檢查了我的垃圾,但沒有...所以我相信我的代碼不是發送郵件....不知道爲什麼。

我可能錯過了一些設置...但由於這是我第一次使用PHP郵件,我不知道什麼設置丟失。在閱讀Mail的文檔...沒有找到任何這樣的要求/設置。任何幫助將非常感激。

+0

不知道,你可以使用smtp.live.com從你的腳本,他們可能不會接受你的連接。 – Mario

+0

你在設置你的hotmail用戶名/密碼嗎?這個問題可能有助於[鏈接](http://stackoverflow.com/questions/9430412/how-to-set-smtp-username-and-password-using-ini-set) – Re0sless

+0

希望這個問題可能現在被整理出來。是嗎? – Jinandra

回答

-1

如果不進行身份驗證,則無法使用smtp.live.com。

+0

增加了以下代碼 ini_set('smtp_user','[email protected]'); ini_set('smtp_password','mypass'); ini_set('smtp_start_tls','1'); 但仍然沒有郵件。而且,當我嘗試發送郵件而不驗證自己時,是否應該給出錯誤? –

0

如果你不介意使用PHPMailer的LIB試試這個:

<?php 
    require("PHPMailer_5.2.4/class.phpmailer.php"); 

    $mail = new PHPMailer(); 
    $mail->SMTPDebug = true; 
    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->SMTPAuth = true; // SMTP authentication 
    $mail->Host  = "StartTLS://smtp.live.com"; // SMTP server 
    $mail->Port  = 587; // SMTP Port 
    $mail->Username = "username"; // SMTP account username 
    $mail->Password = "xxx";  // SMTP account password 

    $mail->SetFrom('from_emailid', 'yourname'); // FROM 
    $mail->AddReplyTo('replyto_emailid', 'name'); // Reply TO 

    $mail->AddAddress('recepeint_emailid'); // recipient email 

    $mail->Subject = "First SMTP Message"; // email subject 
    $mail->Body  = "Hi! \n\n This is my first e-mail sent through live SMTP using PHPMailer."; 

    if(!$mail->Send()) { 
     echo 'Message was not sent.'; 
     echo 'Mailer error: ' . $mail->ErrorInfo; 
    } else { 
     echo 'Message has been sent.'; 
    } 
+0

我剛剛嘗試過並測試了代碼,它對我來說工作得很好。你能否指出你收到的任何特定錯誤。 – Jinandra