简体   繁体   English

通过PHP发送邮件

[英]Sending Mail through PHP

Here i have a problem when iam sending a mail.It is delevering properly but when iam trying designing the message body with HTML tags it sending the same html tags to my email inbox.How can i overcome this please tell me. 在这里我有一个问题,当我发送邮件。它正确删除,但当我尝试用HTML标签设计邮件正文时,它发送相同的HTML标签到我的电子邮件收件箱。我怎么克服这个请告诉我。

Here the PHP code: 这里是PHP代码:

$to = "$email";
$subject = "Test mail";
$message = '<!Doctype html><html><head><title>Confirm Link</title></head><body><div style="color:blue">Thank u for registering with us </div>
<div> Hi'.$name.' Please click the below link to activate your accont</div><div><a href="http://www.websitename.com/test2/activation.php?id='.$uid.'&name='.$name.'&mail='.$email.'">Active your account now</a></div> </body></html>';

$from = "abc@gmail.com";
$headers = "From:" . $from;

Here my deliverd email inbox message: here designing not working it display same as my program code.Please help me. 这里我发送的电子邮件收件箱消息:这里设计不工作它显示与我的程序代码相同。请帮助我。

Confirm LinkThank u for registering with us HiSrinivas Please click the below link to activate your accont Active your account now 确认LinkThank u注册我们HiSrinivas请点击以下链接激活您的帐户立即激活您的帐户

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Note: 注意:

If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime. 如果打算发送HTML或其他复杂邮件,建议使用PEAR包»PEAR :: Mail_Mime。

Reference 参考

Send an HTML email: 发送HTML电子邮件:

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$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: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

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

The problem may be that you are not setting the mail headers. 问题可能是您没有设置邮件标题。 Try this: 尝试这个:

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM