将附件(jpg)添加到此PHP邮件脚本
我试图添加一个代码,允许我通过php发送附件(jpg) 我当前的脚本:将附件(jpg)添加到此PHP邮件脚本,php,email,jpeg,attachment,send,Php,Email,Jpeg,Attachment,Send,我试图添加一个代码,允许我通过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($in
<?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 = $random_picture
及
这样脚本就可以在我每次加载它的时候将一个random number.jpg截图并发送出去
谢谢!:) 我想下面这样做(不需要测试) 你可以从表格中得到帮助 你的身体部位需要做一些改变,比如:
$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));
您现在发送的电子邮件与您现在发送的电子邮件相同
注:
看看
编辑:
完整代码如下:
<?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>");
}
?>
你可以在网站上获得帮助,是的,但我的PHP不是很好。我试过了,但我不知道在哪里添加到正确的行:(看起来很棒!但我绝对是一个php noob。我不知道在脚本中放置相关代码的位置:(有人可以发布包含新附件脚本的完整脚本吗?这将对我帮助很大!)!
$randomPicArr = array('a.jpg','b.jpg','c.jpg','d.jpg','e.jpg');
$randomNum = rand(0,5);
$random_picture = $randomPicArr[$randomNum];
$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));
<?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>");
}
?>