Fun*_*ner 5 php arrays email random
经过几个小时的尝试自己解决这个问题后,我正在寻求帮助.
我有以下代码,我想通过电子邮件将结果发送到电子邮件.
这是我的代码:
$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);
Run Code Online (Sandbox Code Playgroud)
到目前为止,我能够将结果回显到屏幕,但无法通过电子邮件发送结果.
发送电子邮件非常简单,例如:
<?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>");
}
?>
Run Code Online (Sandbox Code Playgroud)
类似这样的东西应该可以工作,如果没有,邮件服务器可能没有在 Web 服务器上正确配置。