PHP,不要在电子邮件上获取图像

时间:2015-08-07 06:07:25

标签: php image email

我正在用PHP编写代码来发送电子邮件。一切正常,但是当我收到电子邮件时,我看不到图像。

我在php中有这个代码:

error_reporting(0);

$name = $_POST['ev-name'];
$email= $_POST['ev-mail'];
$phone = $_POST['ev-phone'];
$date = $_POST['ev-date'];
$type = $_POST['ev-type'];
$people = $_POST['ev-people'];
$notes = $_POST['ev-notes'];

$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'From: '.$_POST['ev-mail']."\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$para = 'tlucena4@gmail.com';
$asunto = 'Event Enquiry';


$mensaje = '
    <html>
        <head>
            <title>Dining Concepts Mobile - Event Enquiry</title>
        </head>
        <body style="width: 80%; margin: auto;">
            <div style="width: 100%; background-color: #6b011a; border-bottom: 2px solid #32060f; color: #ffffff; font-weight: bold; padding: 20px 10px;"><img src="http://www.diningconcepts.com/pics/header-logo-dc.png" alt="Dining Concepts logo" /></div>
                <div style="width: 100%; background-color: #f2f2f2; padding: 20px 10px;">
                    <div><h3>We have received a new Event Enquiry</h3></div>
                    <div style="margin-bottom: 20px;"><p style="color:#6b011a;"><b>Personal Data</b></p>
                        <div><b>From:&nbsp;</b>'.$name.'</div>
                        <div><b>Email:&nbsp;</b>'.$email.'</div>
                        <div><b>Phone:&nbsp;</b>'.$phone.'</div>
                    </div>
                    <div style="margin-bottom: 20px;"><p style="color:#6b011a;"><b>Event Data</b></p>
                        <div><b>Date of the event:&nbsp;</b>'.$date.'</div>
                        <div><b>Type of event:&nbsp;</b>'.$type.'</div>
                        <div><b>Number of people:&nbsp;</b>'.$people.'</div>
                    </div>
                    <div style="margin-bottom: 30px;"><b style="color:#6b011a;">Customer Message:&nbsp;</b>'.$notes.'</div> 
                    <div><b style="color:#6b011a;">This Message was sent:&nbsp;</b>'.date('d/m/Y').'</div>
                </div>
            <div style="text-align: center; width: 100%; padding: 6px; color:#fff; background-color: #6b011a;">Dining Concepts '.date('Y').' - All Rights Reserved</div>
        </body>
    </html>
';

if (mail($para, $asunto, utf8_decode($mensaje), $header)) {
  echo "<script>alert('Mail was sent !');</script>";
  echo "<script>document.location.href='http://localhost/diningconcepts/public/'</script>";
  }
  else
  {
  echo "<script>alert('Mail was not sent. Please try again later');</script>";
  }

$name = $_POST['ev-name']; $email= $_POST['ev-mail']; $phone = $_POST['ev-phone']; $date = $_POST['ev-date']; $type = $_POST['ev-type']; $people = $_POST['ev-people']; $notes = $_POST['ev-notes']; $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'From: '.$_POST['ev-mail']."\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $para = 'tlucena4@gmail.com'; $asunto = 'Event Enquiry'; $mensaje = ' <html> <head> <title>Dining Concepts Mobile - Event Enquiry</title> </head> <body style="width: 80%; margin: auto;"> <div style="width: 100%; background-color: #6b011a; border-bottom: 2px solid #32060f; color: #ffffff; font-weight: bold; padding: 20px 10px;"><img src="http://www.diningconcepts.com/pics/header-logo-dc.png" alt="Dining Concepts logo" /></div> <div style="width: 100%; background-color: #f2f2f2; padding: 20px 10px;"> <div><h3>We have received a new Event Enquiry</h3></div> <div style="margin-bottom: 20px;"><p style="color:#6b011a;"><b>Personal Data</b></p> <div><b>From:&nbsp;</b>'.$name.'</div> <div><b>Email:&nbsp;</b>'.$email.'</div> <div><b>Phone:&nbsp;</b>'.$phone.'</div> </div> <div style="margin-bottom: 20px;"><p style="color:#6b011a;"><b>Event Data</b></p> <div><b>Date of the event:&nbsp;</b>'.$date.'</div> <div><b>Type of event:&nbsp;</b>'.$type.'</div> <div><b>Number of people:&nbsp;</b>'.$people.'</div> </div> <div style="margin-bottom: 30px;"><b style="color:#6b011a;">Customer Message:&nbsp;</b>'.$notes.'</div> <div><b style="color:#6b011a;">This Message was sent:&nbsp;</b>'.date('d/m/Y').'</div> </div> <div style="text-align: center; width: 100%; padding: 6px; color:#fff; background-color: #6b011a;">Dining Concepts '.date('Y').' - All Rights Reserved</div> </body> </html> '; if (mail($para, $asunto, utf8_decode($mensaje), $header)) { echo "<script>alert('Mail was sent !');</script>"; echo "<script>document.location.href='http://localhost/diningconcepts/public/'</script>"; } else { echo "<script>alert('Mail was not sent. Please try again later');</script>"; }

检查电子邮件的布局:

email template

有什么想法像往常一样在这个网站上拯救我的生命吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

  

我检查了你的图片路径http://www.diningconcepts.com/pics/header-logo-dc.png。路径包含图像。

标题应该是

$header = "From: $email";
$header  .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type: text/html; charset=iso-8859-1";

在邮件中删除utf8_decode()