PHP-在mailsender中的$ message变量内回显

时间:2018-11-06 16:39:37

标签: php

您好,我在mailsender的PHP回显代码中有一个变量$folder有问题。一切都很好,但是代码没有显示图像,可能是我在这里弄错了。

<?php 
if(isset($_POST['submit'])){
    $to = "mail@my.mail.com"; // this is your Email address
    $from = "MYSELF"; // this is the sender's Email address
    $first_name = "A";
    $last_name = "B";
    $subject = "Hello!";
    $subject2 = "X";
    $headers = "From:" . $from;
    $headers = "MIME-Version: 1.0\r\n";
    $headers = "Content-Type: text/html; charset=UTF-8\r\n";
    $message= "
    <tr>
        <td><b>Subname</b></br>".$_POST["Subname"]."</td>
        <td rowspan='10'></br><img src='".$folder."'width='200' height='200'></td>
    </tr>";
    mail($to,$subject,$message,$headers);
    }
?>

在普通的PHP代码中,我已经拥有了这个图像,并且图像可以正确显示,但是我在邮件发送器中将“ echo”移到了$message上。

<?php

    if(isset($_POST['submit'])){

        $file_name = $_FILES['file']['name'];
        $temp_name = $_FILES['file']['tmp_name'];
        $folder = "upload/".$file_name;

        move_uploaded_file($temp_name, $folder);
        echo "<img src='$folder' width='200' height='200'>";
    }
?>

1 个答案:

答案 0 :(得分:0)

您的第二个PHP代码$folder指向目录,并且可以正常工作。

但是要使其在您的$message中起作用,$ folder必须是指向图像的链接。像http://example.com/image.png

<?php 
if(isset($_POST['submit'])){ 
    $folder = "http://example.com/image.png";

    $to = "mail@my.mail.com"; // this is your Email address
    $from = "MYSELF"; // this is the sender's Email address
    $first_name = "A";
    $last_name = "B";
    $subject = "Hello!";
    $subject2 = "X";
    $headers = "From:" . $from;
    $headers = "MIME-Version: 1.0\r\n";
    $headers = "Content-Type: text/html; charset=UTF-8\r\n";
    $message= "
    <tr>
        <td><b>Subname</b></br>".$_POST["Subname"]."</td>
        <td rowspan='10'></br><img src='".$folder."'width='200' height='200'></td>
    </tr>";
    mail($to,$subject,$message,$headers);
    }
?>