2013-09-28 144 views
1

我想發送使用PHP郵件功能在Linux平臺上的HTML圖像郵件。有一個問題,當我試圖發送簡單的HTML內容,然後它成功地交付給它的訂戶。但是當我嘗試發送包含少量圖像的電子郵件時,則無法傳送它。下面是兩個簡單的html傳遞的代碼1。 2沒有交付。如何發送圖像郵件使用PHP郵件功能

<?php 
$to = "[email protected], [email protected]"; 
$subject = "HTML email"; 

$message = " 
<html> 
<head> 
<title>HTML email</title> 
</head> 
<body> 
<p>This email contains HTML Tags!</p> 
<table> 
<tr> 
<th>Firstname</th> 
<th>Lastname</th> 
</tr> 
<tr> 
<td>John</td> 
<td>Doe</td> 
</tr> 
</table> 
</body> 
</html> 
"; 

// Always set content-type when sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 

// More headers 
$headers .= 'From: <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 

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

代碼2:

<?php 
    //change this to your email. 
    $to = "[email protected]"; 
    $from = "[email protected]"; 
    $subject = "Hello! This is HTML email"; 

    //begin of HTML message 
$message= <<<EOF 
<html> 
    <body bgcolor="#DCEEFC"> 
    <center> 
     <b>Looool!!! I am reciving HTML email......</b> <br> 
     <font color="red">Thanks Mohammed!</font> <br> 
     <a href="http://www.maaking.com/">* maaking.com</a> 
    </center> 
     <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine 
    </body> 
</html> 
EOF; 
    //end of message 
    $headers = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 

    //options to send to cc+bcc 
    //$headers .= "Cc: [email][email protected]m[/email]"; 
    //$headers .= "Bcc: [email][email protected][/email]"; 

    // now lets send the email. 
    mail($to, $subject, $message, $headers); 

    echo "Message has been sent....!"; 
?> 
+1

作爲提示,用PHP發送郵件並不容易。最好使用像Swiftmailer這樣的庫文件,這使得這個過程變得更加簡單。看看這裏:http://swiftmailer.org/docs/messages.html – Reflic

+0

謝謝Reflic,但我需要使用PHP來做到這一點。我會看看並嘗試使用您提供的文檔。但是,你有什麼想法,我怎麼能使用PHP ... –

+0

可能的重複:[HEREDOC語法](http://stackoverflow.com/questions/11457073/sending-html-email-from-php-with-variables ) – aaron

回答

0
working through out the day i corrected the code by which i am able to send image mailer below is the code-: 
<?php 
$to= '[email protected]' . ','; 
$to .= '[email protected]'; 
$sub='test1'; 
$msg= <<<EOF 
    <html> 
    <body> 
    <table> 
    <tr> 
     <td><img src="http://d32vlg867bsa1v.cloudfront.net/z/prod/w/2/i/zovi-logo2.png" /> 
     </td> 
    </tr> 
    </table> 
    </body> 
    </html> 
EOF; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Additional headers 
$headers .= 'From: <[email protected]>' . "\r\n"; 


mail($to,$sub,$msg,$headers); 
?> 

,我還是不斷的工作,以發送高度定製郵件,將描述如何能一次,我發現它可以怎樣做,如果有人知道,請幫助或至少指導如何做到這一點。

相關問題