1

所有信息都来自一个表格。提交表单时,我使用 phpmail()将所有信息发送到我的邮箱,但我不知道如何格式化提交表单中的所有信息。

有没有办法格式化显示为以下样式的电子邮件。

在此处输入图像描述

如果使用mail()可以得到,我该怎么做?或者还有其他方法可以得到,谢谢。

4

3 回答 3

2

不要使用邮件()。

而是使用 phpmailer 类。 http://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.phpmailer.php http://phpmailer.worxware.com/

您在代码中调用该类。

require "includes/class.phpmailer.php";

然后,您使用 HTML 和一些常识来格式化您的邮件字符串。要格式化您想要的方式,您可以使用 p 和换行符。图片,链接,大部分你认为在 html 中使用的东西。它对我来说效果很好。

提示:您不想包含外部 css,因此您的 html 可能必须有点老派,使用文本对齐和设置宽度使用样式。

编辑。调用包含

require "includes/class.phpmailer.php";

然后,设置一些变量,例如您的消息……进行格式化。

$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($emailAddress, "Your Reply Name");  // could be $replayemail if set
$mail->AddAddress($mailto);                           // who you are emailing  
$mail->SetFrom($emailAddress, "Your From Name");      // from email
$mail->Subject = $subject;                            // keep it simple, email header
$mail->MsgHTML($message);                             // format fun stuff in $message 
$mail->Send();
于 2012-12-15T04:22:25.173 回答
0

Set the headers like this

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
mail($to,$subject,$message,$headers);

This would allow you to send html in mail.You can apply styling too.

于 2012-12-15T05:07:11.863 回答
0

您需要了解 PHP HTML 邮件。

IMO PHP 初学者最好的学校:http: //www.w3schools.com/php/func_mail_mail.asp

于 2012-12-15T04:11:18.073 回答