0

我试图添加一个代码,它允许我通过 php 发送附件(jpg)!

我当前的脚本:

<?php
$input = array("@[XXXX:0]", "@[XXXX:0]", "@[XXX:0]", "@[XXX:0]", "@[XXX:0]", "@[XXX:0]",                 "@[XXX:0]", "@[XXX:0]", "@[XXX:0]", "@[XXX:0]", "@[XXX:0]", "@[XXX:0]");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]];
?>

<?php
 $to = "XXX@XXX.com";
 $subject = "Wuensche euch allen ein schoenes Wochenende.
Sehn uns hier: @[XXXXXXXXXXXX:0]!
Shouts heute gehen an ". $input[$rand_keys[0]]." <3.
Kuss, XXX.";
 $body = "bacon";
 if (mail($to, $subject, $body)) {
   echo("<p>Message to Facebook successfully sent!</p>");
  } else {
   echo("<p>Message to Facebook failed!</p>");
  }
 ?>

所以像:

$file = picture.jpg

(在同一目录中!)

如果可行:

我们可以做类似的事情吗

$file = $random_picture

$random_picture = 1.jpg 2.jpg 3.jpg 4.jpg etc.

这样脚本会随机生成一个 number.jpg 并在我每次加载时发送它?

谢谢!:)

4

2 回答 2

1

您可以通过HTML EMAIL WITH JPEG ATTACHMENTS TUTORIAL获得帮助。

你需要像这样改变你的身体部位:

$pics = array('1.jpg', '2.jpg', '3.jpg', '4.jpg');
//Pick key of the random image
$random_key = array_rand($pics,1);

$file = file_get_contents("YOUR_ABSOLUTE_URL".$pics[$random_key]);

$body.= "Content-Type: image/jpg; name=\"".$pics[$random_key]."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-disposition: attachment; file=\"".$pics[$random_key]."\"\r\n"
."\r\n"
.chunk_split(base64_encode($file)); 

你现在发送电子邮件。

笔记:

看看array_rand

编辑:

完整代码如下:

<?php
$to = "XXX@XXX.com";
$subject = "YOUR_SUBJECT";
$body = "bacon";
$pics = array('1.jpg', '2.jpg', '3.jpg', '4.jpg');
//Pick key of the random image
$random_key = array_rand($pics,1);

$file = file_get_contents($pics[$random_key]);

$body.= "Content-Type: image/jpg; name=\"".$pics[$random_key]."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-disposition: attachment; file=\"".$pics[$random_key]."\"\r\n"
."\r\n"
.chunk_split(base64_encode($file));

if (mail($to, $subject, $body)) {
    echo("<p>Message to Facebook successfully sent!</p>");
} else {
    echo("<p>Message to Facebook failed!</p>");
}
?>
于 2013-11-07T11:57:38.553 回答
0

我猜会像下面这样(未经测试);

$randomPicArr = array('a.jpg','b.jpg','c.jpg','d.jpg','e.jpg');
$randomNum = rand(0,5);
$random_picture = $randomPicArr[$randomNum];
于 2013-11-07T11:52:25.333 回答