1

这是我需要做的。我需要能够动态生成自定义电子邮件。我一直在使用 PHP 的 mail() 函数,但有人鼓励我尝试使用 phpmailer 或 Zendmail。但它似乎无法处理自定义电子邮件。

我需要做的是能够从表单中获取值并将它们插入到消息的正文中。我一直在做:

$message = '<html><body><p>First name: ' $first . '<br/><br/>';
$message .= ...(rest of message)

然后我做:

mail($recipient, $subject, $message, $headers);使用正确的 HTML 标头。

有没有办法用 phpmailer 或 Zendmail 做我想做的事?有没有办法在 OOP 中做到这一点,而不是可以改善那些变得非常冗长的页面?我会很感激一些指导。

4

2 回答 2

2

使用 phpmailer 你可以试试下面的代码。

$message = '<html><body><p>First name: '. $first . '<br/><br/>';

$mailer = new PHPMailer();
// other fields / properties
$mailer->Subject = $subject;
$mailer->AddAddress($receipient);
$mailer->IsHTML(true);
$mailer->Body = $message;
$mailer->Send();

您需要设置其他字段才能使其正常工作。

于 2010-12-15T18:39:07.930 回答
0

是的,拥有邮件库的要点之一是能够创建复杂的电子邮件(更容易)。我也会推荐 SwiftMailer。

http://swiftmailer.org

于 2010-12-15T18:33:12.147 回答