具有dyanmic值的HTML邮件 [英] HTML mail with dyanmic values

查看:106
本文介绍了具有dyanmic值的HTML邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  $ message ='< html>< body>< p>名字: $第一。 <峰; br /><峰; br />; 
$ message。= ...(其余的消息)

然后我做: / p>

mail($ recipient,$ subject,$ message,$ headers); 使用HTML的正确标题。 / p>

有没有办法用phpmailer或Zendmail做我想要的?有没有办法在OOP中做到这一点,可能会改善什么是非常冗长的页面?我会感谢一些指导。

解决方案

使用phpmailer可以尝试以下代码。

  $ message ='< html>< body>< p>名字:'。 $第一。 <峰; br /><峰; br />; 

$ mailer = new PHPMailer();
//其他字段/属性
$ mailer-> Subject = $ subject;
$ mailer-> AddAddress($ receipient);
$ mailer-> IsHTML(true);
$ mailer-> Body = $ message;
$ mailer-> Send();

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


Here is what I need to do. I need to be able to dynamically generate custom emails. I have been using PHP's mail() function, but I have been encouraged to try phpmailer or Zendmail. But it doesn't seem to be able to handle custom emails.

What I need to do is be able to grab values from the form and insert them into the body of the message. I've been doing:

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

Then I do:

mail($recipient, $subject, $message, $headers); using the right headers for HTML.

Is there a way to do what I want with phpmailer or Zendmail? Is there a way to do this in OOP instead that might improve on what are getting to be very lengthy pages? I'd appreciate some guidance.

解决方案

Using phpmailer you could try the code below.

$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();

you'd need to set the other fields for it to work properly though.

这篇关于具有dyanmic值的HTML邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆