如何使用php mail()在收件箱邮件中显示邮件发件人个人资料图片和标题?

时间:2016-11-16 06:21:27

标签: php html-email

发送带有PHP的电子邮件时遇到问题 问题是我的电子邮件标题,变量是空白

我的电子邮件的屏幕截图:

enter image description here

我使用我的工作电子邮件地址发送电子邮件。 我的脚本就像这样

public static function header($from, $cc = false, $replyTO = null) {
    $headers = "From: " . $from . "\r\n";
    if ($replyTO) {
    $headers .= "Reply-to: ". $replyTO ."\r\n"; }
    if ($cc) {
    $headers .= "CC: ". $cc ."\r\n"; }
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    return $headers;
}

public static function top() {
    return file_get_contents('email/top.php');
}

public static function footer() {
    return file_get_contents('email/bottom.php');;
}

public static function output( $url ) {

    $message = self::top();
    $message .= $url;
    $message .= self::footer();

    return $message;
}

public static function send($from, $to, $subject, $content) {
    if ( mail($to, $subject, $content, self::header($from)) ) {
        return true;
    }

    return false;
}

任何解决方案?提前谢谢你

2 个答案:

答案 0 :(得分:3)

For From name:

尝试以下方法:

public static function header($from,$sender_name='', $cc = false, $replyTO = null) {
    $headers = "From: ".$sender_name."<" . $from . "> \r\n";
    if ($replyTO) {
    $headers .= "Reply-to: ". $replyTO ."\r\n"; }
    if ($cc) {
    $headers .= "CC: ". $cc ."\r\n"; }
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    return $headers;
}

答案 1 :(得分:1)

代表名称

var student = {
            role: function () {

                var studRole = document.getElementById("student");
                var roleStud = studRole.options[studRole.selectedIndex].value;

                switch (roleStud) {
                    case 'Admin':
                        alert("Welcome Admin");
                        break;
                    default:
                    }
                  }
                }

我假设图像与谷歌+帐户绑定,您可以用他们注册您当前的电子邮件然后只需添加您的图像和vala