我正在使用PHP代码发送电子邮件 这是我的代码
<?php
$message ="<html><head><title>Enquiry Email</title></head><body>";
$message .= '<div style="float:left"><img src="url" /></div>';
$message .="You got a new Enquiry From Following <br/>";
foreach($_POST as $key =>$value){
if(!empty($value)){
$message.="<strong>".ucwords($key)."</strong>: ".$value."<br/>";
}
}
$message .= 'test content</body></html>';
//echo $message; exit;
//$message=rtrim(chunk_split(base64_encode($message)));
$to = 'test@someeamil.com';
$subject = 'New Enquiry';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
//$headers . ='Content-Transfer-Encoding: base64';
$headers .= "From: test email<test@someemail.in>\r\n";
mail($to, $subject, $message, $headers);
?>
我收到了这种格式的电子邮件
Subject: New Enquiry
Content-Type: text/html; charset=ISO-8859-1
From: test email<test@someemail.in>
Message-Id: <20120110134752.3AE7B2A91E@somename.in> Date: Tue, 10 Jan 2012 19:17:52 +0530 (IST) X-Brightmail-Tracker: AAAAAA== X-Brightmail-Tracker: AAAAAA==
<html><head><title>Enquiry Email</title></head><body><div style="flaot:left"><img src="linkurl" /></div>You got a new Enquiry From Following <br/><strong>Customer</strong>: Customer<br/><strong>Title</strong>: Mr.<br/><strong>Fistname</strong>: gurpreet<br/><strong>Lastname</strong>: Singh<br/><strong>Telephone</strong>: 212344556<br/><strong>Email</strong>: test@test.com<br/><strong>Address</strong>: addrewss Vi<br/><strong>Catalogue</strong>: Catalogue<br/><strong>Meeting</strong>: Meeting at my home / office<br/><strong>Internet</strong>: Internet<br/>some name </body></html>
但是现在当我尝试发送gmail服务器时,它会以HTML格式提供正确的输出。
谢谢!
答案 0 :(得分:0)
尝试使用第三方电子邮件软件库(例如SwiftMailer)以便更轻松地处理电子邮件。
答案 1 :(得分:0)
标题应格式正确,删除示例代码如下:
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n"
. "Content-Type: multipart/mixed;\n"
. " boundary=\"{$mime_boundary}\"";
$message ="--{$mime_boundary}\n"
. "Content-Type: text/html; charset=\"iso-8859-1\"\n"
. "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
您的From
代码必须在MIME-Version
之前。上面的代码工作正常。重新排列标题。