HTML mail with dyanmic values

拟墨画扇 提交于 2019-12-24 10:19:09

问题


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.


回答1:


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.




回答2:


Yes, one of the main points of having a mail library is to be able to create complex emails (more easily). I would also recommend SwiftMailer.

http://swiftmailer.org



来源:https://stackoverflow.com/questions/4453505/html-mail-with-dyanmic-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!