Sending results from random array to php email

I ask for help after several hours trying to figure it out myself.

I have the following code that I would like to send an email via email.

Here is my code:

$emailme = "myemail@somewhere.com";

$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);

So far, I could display the results on the screen, but could not send the results by email.

+5
source share
1 answer

Sending email is pretty straight forward, for example:

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

$to = "recipient@example.com";
$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>");
 }
?>

Something like this should work, if not, the mail server may not be configured correctly on the web server.

+4
source

All Articles