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....!";
?>
作爲提示,用PHP發送郵件並不容易。最好使用像Swiftmailer這樣的庫文件,這使得這個過程變得更加簡單。看看這裏:http://swiftmailer.org/docs/messages.html – Reflic
謝謝Reflic,但我需要使用PHP來做到這一點。我會看看並嘗試使用您提供的文檔。但是,你有什麼想法,我怎麼能使用PHP ... –
可能的重複:[HEREDOC語法](http://stackoverflow.com/questions/11457073/sending-html-email-from-php-with-variables ) – aaron