2014-04-28 35 views
-2

我正在嘗試使用html內容發送電子郵件。如何發送帶HTML內容的電子郵件

我想它插入一些圖片,但我不知道我怎麼能做到這一點,我在這裏的代碼:

<?php 
if(isset($_POST['submit'])){ 
$to  = $_POST['to']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: '.$to.' ' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

mail($to, $subject, $message, $headers); 

} 

?> 

<form method="POST"> 
<input type="text" placeholder="from" name="from" /> 

<input type="text" placeholder="to" name="to" /> 
<input type="text" placeholder="Subject" name="subject" /> 
<textarea type="text" placeholder="Message" name="message"></textarea> 
<input name="submit" type="submit" /> 
</form> 

謝謝你們

+0

http://php.net/manual/en/function.mail.php#example-3471 – j08691

+0

我建議你谷歌你的問題的學科。插入圖片是** HTML 101 ** –

回答

2

只需要適當的標題傳遞給郵件功能:

// Send HTML Message 
$headers = 'MIME-Version: 1.0' . PHP_EOL; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL; 
$headers .= 'From: example name <[email protected]>' . PHP_EOL; 
mail('[email protected]', 'Subject', $output, $headers); 
2
$to = "$email"; 
    // Change this to your site admin email 
    $from = "[email protected]"; 
    $subject = "Welcome to MYSITE.COM"; 
    //Begin HTML Email Message where you need to change the activation URL inside 
    $message = '<html> 
    <body bgcolor="#FFFFFF"> 
    Dear ' . $firstname . ', 
    <br /><br /> 
    Thank you for joining MYSITE.COM. 
    <br /><br /> 
    You can now start shopping on our website and enjoy all of our services. 
    Please click on the link bellow to go to our website &gt;&gt; 
    <a href="http://www.MYSITE.COM">http://www.MYSITE.COM</a> 
    <br /><br /> 
    Your Login Details is as follows: 
    <br /><br /> 
    E-mail Address: ' . $email . ' <br /> 
    Password: ' . $password . ' 
    <br /><br /> 
    Regards 
    MYSITE.COM 
    </body> 
    </html>'; 
    // end of message 
    $headers = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 
    $to = "$to"; 
    // Finally send the activation email to the member 
    mail($to, $subject, $message, $headers); 

您可以編輯代碼,以滿足您的需求。但它應該可以幫助您瞭解如何直接從PHP發送HTML電子郵件。

相關問題