2012-06-12 27 views
5

我在尋求幫助,經過幾個小時試圖找出自己。從隨機數組發送結果到電子郵件php

我有下面的代碼,我想通過電子郵件發送結果給我。

這裏是我的代碼:

$emailme = "[email protected]"; 

$subject = "Randomly selected from array"; 
$headers = "From: $emailme\n"; 

$message = "Here is the Randomly selected from array.\n 
Random text: $r_array"; 

$r_array=file('file.txt'); 
shuffle($r_array); 
$output = "<p><center><b>The Randomly Selected Text is:</b></p><b>" . 
$r_array[0] . "All done, echoing results."; 

mail($emailme,$subject,$message,$headers); 

到目前爲止,我能夠呼應結果的屏幕,但我無法通過電子郵件發送的結果。

+0

您的代碼發送電子郵件在哪裏? – Viezevingertjes

+1

您還應該放置用於發送郵件的代碼 –

+0

現在將用完整的代碼進行更新。 –

回答

4

發送電子郵件是非常簡單的,例如:

<?php 
$r_array=file('file.txt'); 
shuffle($r_array); 

$to = "[email protected]"; 
$subject = "Random Selected Text"; 
$body = "<p><center><b>The Randomly Selected Text is:</b></p><b>" . $r_array[0] . "All done, echoing results."; 
if (mail($to, $subject, $body)) { 
    echo("<p>Message successfully sent!</p>"); 
} else { 
    echo("<p>Message delivery failed...</p>"); 
} 
?> 

像這樣的事情應該工作,如果沒有,郵件服務器可能無法正確在Web服務器上配置。

+0

謝謝。我收到電子郵件,這是電子郵件中沒有顯示的隨機數組的實際結果。我嘗試了你的代碼,但它仍然沒有顯示$ r_array [0] –

+0

的結果。對不起,邁克爾,我的錯在上面另一個評論中說過。在消息傳出之前定義$ r_array。但是,您的代碼非常幫助我,謝謝。乾杯〜 –