我正在寻求帮助,经过几个小时的尝试自己弄清楚这一点。
我有以下代码,我想通过电子邮件将结果发送到电子邮件。
这是我的代码:
$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);
到目前为止,我能够将结果回显到屏幕,但无法通过电子邮件发送结果。
发送电子邮件非常简单,例如:
<?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>");
}
?>
这样的事情应该可以工作,否则,邮件服务器可能未在 Web 服务器上正确配置。