如何使用PHP发送带格式图片的HTML格式电子邮件? 我想要一个页面,其中包含一些设置和通过电子邮件发送到地址的HTML输出。我该怎么办? 主要问题是附上files.how我可以做到这一点?通过PHP在电子邮件中发送HTML?
回答
这是很简单的,在服务器上保留的图像和发送PHP + CSS来他们...
$to = '[email protected]';
$subject = 'Website Change Reqest';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
正是这一行告诉邮件程序和电子邮件包含收件人(希望)以及形成的HTML,这将需要解释:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
这是我得到的信息。(link...)
您需要安全但链接...
最简单的方法可能就是使用Zend Framework或任何其他框架(如CakePHP或Symphony)。
您也可以使用标准的mail
函数,但您需要更多的关于如何附加图片的知识。
或者,只将图像托管在服务器上而不是附加它们。发送HTML邮件记录在mail
功能文档中。
您需要使用图像的绝对路径编码您的html。通过绝对路径意味着你必须上传图像在服务器和图像的src
属性,你必须给这个直接路径<img src="http://yourdomain.com/images/example.jpg">
。
以下是为您REFFERENCE PHP代码: - 它从http://www.php.net/manual/en/function.mail.php
<?php
// multiple recipients
$to = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<p>Here are the birthdays upcoming in August!</p>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
采取我有这个代码,它将完美运行我的网站
public function forgotpassword($pass,$name,$to)
{
$body ="<table width=100% border=0><tr><td>";
$body .= "<img width=200 src='";
$body .= $this->imageUrl();
$body .="'></img></td><td style=position:absolute;left:350;top:60;><h2><font color = #346699>PMS Pvt Ltd.</font><h2></td></tr>";
$body .='<tr><td colspan=2><br/><br/><br/><strong>Dear '.$name.',</strong></td></tr>';
$body .= '<tr><td colspan=2><br/><font size=3>As per Your request we send Your Password.</font><br/><br/>Password is : <b>'.$pass.'</b></td></tr>';
$body .= '<tr><td colspan=2><br/>If you have any questions, please feel free to contact us at:<br/><a href="mailto:[email protected]" target="_blank">[email protected]</a></td></tr>';
$body .= '<tr><td colspan=2><br/><br/>Best regards,<br>The PMS Team.</td></tr></table>';
$subject = "Forgot Password";
$this->sendmail($body,$to,$subject);
}
邮件功能
function sendmail($body,$to,$subject)
{
//require_once 'init.php';
$from='[email protected]';
$headersfrom='';
$headersfrom .= 'MIME-Version: 1.0' . "\r\n";
$headersfrom .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersfrom .= 'From: '.$from.' '. "\r\n";
mail($to,$subject,$body,$headersfrom);
}
图片url功能用于如果你想改变你有图片的图片ge只有一个功能我有很多邮件功能,比如忘记密码创建用户那里我使用图片url功能可以直接设置路径。
function imageUrl()
{
return "http://".$_SERVER['SERVER_NAME'].substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/")+1)."images/capacity.jpg";
}
使用PHPMailer的,
要发送HTML邮件,你必须只设置$ MAIL-> isHTML(),你可以用HTML代码来设置你的身体
这是一个良好的书面教程:
rohitashv.wordpress.com/2013/01/19/how-to-send-mail-using-php/
的技巧是建立HTML身体部位时,要知道图片的MIME部分的内容ID。 它归结为使img标签
https://github.com/horde/horde/blob/master/kronolith/lib/Kronolith.php
看一下函数buildMimeMessage的工作示例。
您可以通过PHP轻松发送带HTML内容的电子邮件。使用以下脚本。
<?php
$to = '[email protected]';
$subject = "Send HTML Email Using PHP";
$htmlContent = '
<html>
<body>
<h1>Send HTML Email Using PHP</h1>
<p>This is a HTMl email using PHP by CodexWorld</p>
</body>
</html>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: CodexWorld<[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
的源代码,并现场演示可以从这里找到 - Send Beautiful HTML Email using PHP
发送HTML电子邮件不是来自发送使用PHP正常邮件太大的不同。需要添加的是php mail()函数头部参数的内容类型。这是一个例子。
<?php
$to = "[email protected]";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>A table as email</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Fname</td>
<td>Sname</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=UTF-8" . "\r\b";
$headers .= 'From: name' . "\r\n";
mail($to,$subject,$message,$headers);
?>
您还可以检查here通过W3Schools的更详细的解释
- 1. 如何在HTML文件中通过PHP发送电子邮件?
- 2. 通过HTML/C发送电子邮件#
- 3. 通过电子邮件发送HTML
- 4. PHP通过HTML邮件发送电子邮件
- 5. 通过PHP在电子邮件中发送HTML页面
- 6. PHP通过SSH发送电子邮件
- 7. 通过jQuery/PHP发送电子邮件
- 8. 通过PHP发送电子邮件
- 9. 通过PHP发送电子邮件?
- 10. 通过php发送电子邮件
- 11. 发送查询从“检查”的HTML框通过电子邮件发送电子邮件通过PHP
- 12. 通过PHP中的表单类型html发送电子邮件
- 13. 使用PHP通过HTML表单发送电子邮件附件
- 14. 通过PHP发送DropDown字段通过PHP到电子邮件
- 15. 通过PHP解析HTML表单并发送电子邮件
- 16. 通过PHP表格发送HTML电子邮件
- 17. 试图通过HTML电子邮件发送PHP表单数据
- 18. 通过PHP发送包含CSS样式表的HTML电子邮件通过PHP
- 19. 在JQuery中通过电子邮件发送html内容
- 20. Html/php电子邮件发送
- 21. 从PHP发送HTML电子邮件
- 22. 使用PHP发送HTML电子邮件
- 23. PHP的HTML电子邮件不发送
- 24. 通过电子邮件发送文件
- 25. 发送HTML电子邮件
- 26. 在PHP中通过本地主机发送电子邮件
- 27. ASP.NET通过电子邮件发送给多个电子邮件
- 28. GAS帮助 - 通过电子邮件发送电子邮件
- 29. 如何通过电子邮件发送电子邮件地址
- 30. 通过PHP通过电子邮件发送表格
是你的问题发送'HTML'代码?或一般使用PHP发送电子邮件? – Adi