Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending results from random array to email php

I am asking for help, after hours of trying to figure this out myself.

I have the following code, which I would like to email results to email.

Here is my code:

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

So far, I am able to echo the results to screen, but am unable to send results via email.

like image 867
Funk Forty Niner Avatar asked Oct 07 '22 13:10

Funk Forty Niner


1 Answers

Sending an email is pretty straight forward, example:

<?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>");
 }
?>

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

like image 170
Viezevingertjes Avatar answered Oct 13 '22 01:10

Viezevingertjes