2014-09-04 108 views
-1

如何使用css來設置將從我的聯繫人表單發送的電子郵件的樣式? 我曾嘗試將CS​​S內聯樣式添加到代碼,但它只是打破它。 我只想添加一條消息和樣式字體並添加圖像/徽標。將css樣式集成到我的電子郵件中發送給聯繫人表單電子郵件


<?php 

include 'config.php'; 

error_reporting (E_ALL^E_NOTICE); 

$post = (!empty($_POST)) ? true : false; 

if($post) 
{ 

<html> 
<h1>This is a test email<h1> 

$name = stripslashes($_POST['name']); 
$email = trim($_POST['email']); 
$subject = stripslashes($_POST['subject']); 
$message = stripslashes($_POST['message']); 

$error = ''; 

</html> 


if(!$error) 
{ 
$mail = mail(WEBMASTER_EMAIL, $subject, $message, 
    "From: ".$name." <".$email.">\r\n" 
    ."Reply-To: ".$email."\r\n" 
    ."X-Mailer: PHP/" . phpversion()); 


if($mail) 
{ 
echo 'OK'; 
} 

} 


} 
?> 

我想它添加到代碼的第一位,因此風格,從接觸的形式發送的電子郵件。

   <span STYLE=\"font-size:20px; color: #333333\"><p>You have recieved a new message enquiry from <a href=\"http://www.google.co.uk\">www.test.co.uk</a> contact form.</p></span> 
       <p> 
       <p> 
       <div STYLE=\"font-size:16px\"> 
       <p><strong>Name:</strong> {$name} </p> 
       <p><strong>Email Address:</strong> {$email}</strong> </p> 
       <p><strong>subject:</strong> {$subject} </p> 
       <p><strong>Message:</strong> {$message} </p> 

       <h3><p></p></h3> 

       <div> 
       <dr /> 
       <span STYLE=\"font-style:italic;font-size:large; color: #333333\">This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</span></div> 

      </body> 
      </html>" 
+0

爲什麼-1需要更多信息? – jl5660 2014-09-04 15:53:27

+0

你意識到你正在向PHP注入原始HTML。 – 2014-09-04 15:54:26

+0

即時通訊新的PHP所以沒有即時通訊不知道什麼即時消息 – jl5660 2014-09-04 15:55:32

回答

0

確保你輸出HTML內容之前關閉<?php標籤,或者使用echo語句,如果你寧願從<?php標籤內寫入HTML。一旦你這樣做了,我懷疑在沒有問題的情況下應用你的CSS會更容易。

更多信息請參見this question

1

你可以做這樣的事情:

<?php 

include 'config.php'; 
error_reporting (E_ALL^E_NOTICE); 
$post = (!empty($_POST)) ? true : false; 

if($post) { 
    echo ' 
    <html> 
    <head> 
     <link href="style.css" rel="stylesheet"> 
    </head> 
    <h1>This is a test email<h1> 
    '; 

    $name = stripslashes($_POST['name']); 
    $email = trim($_POST['email']); 
    $subject = stripslashes($_POST['subject']); 
    $message = stripslashes($_POST['message']); 

    $error = ''; 

    if(!$error) { 
     $mail = mail(WEBMASTER_EMAIL, $subject, $message, 
      "From: ".$name." <".$email.">\r\n" 
      ."Reply-To: ".$email."\r\n" 
      ."X-Mailer: PHP/" . phpversion()); 
     if($mail) { 
      echo 'OK'; 
     } 
    } 
    echo '</html>'; 
} 

?> 

你必須設置你的風格,例如,對CSS文件。

一旦打開PHP代碼(<?php ?>),如果要包括HTML代碼,你有兩個選擇。您可以使用回聲函數(在HTML代碼之前和之後使用""'')編寫該代碼:<?php PHP_CODE echo 'HTML_CODE'; MORE_PHP_CODE ?><?php PHP_CODE echo "HTML_CODE"; MORE_PHP_CODE ?>。您也可以關閉php部分並在稍後重新打開:<?php PHP_CODE ?> HTML_CODE <?php MORE_PHP_CODE ?>

你必須採取你想要的回波函數寫html代碼照顧。如果您打開回顯',則不能將該HTML代碼放在該符號中,因爲您將關閉該回顯句子。使用與"字符的回聲相同的情況。你不能在裏面寫"的html代碼。

+0

謝謝,但我希望h1出現在電子郵件中它自我如何做到這一點? – jl5660 2014-09-05 08:36:17

+0

使用郵件函數:'mail($ recipient,$ subject,$ body,$ headers)',您必須在第三個參數($ body)中包含電子郵件的所有html代碼。 – brunneis 2014-09-05 14:38:45

+0

你能舉個例子嗎? – jl5660 2014-09-08 09:46:00

相關問題