将文本插入邮件正文php

时间:2013-11-08 10:14:23

标签: php oop sendmail

这是我的代码

class Email {
    public $name;
    public $email;
    public $subject;
    public $textarea;
    public $to = "stereoshoots@gmail.com";
    public $header;

    function __construct($name, $email, $subject, $textarea) {
        $this->name = $name;
        $this->email = $email;
        $this->subject = $subject;
        $this->textarea = $textarea;
        $this->header = "From:$this->email \r\n";
        $this->header .= "Имя: $this->name \r\n";
        $this->sendEmail();
    }

    public function sendEmail(){
        if(mail ($this->to,$this->subject,$this->textarea,$this->header)) {
            echo "Отправлено";
        }
        else {
            echo "Ошибка";
        }
    }
}
$obj = new Email($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['textarea']);

我希望在每封邮件的开头都有客户名称:John Doe。我怎么能通过标题来做到这一点?

由于

1 个答案:

答案 0 :(得分:0)

你必须通过标题吗?

为什么不创建新的var

用于html邮件

$this->message=$name."<br><br>".$textarea;

或纯文字

$this->message=$name."\n\n".$textarea;

然后将sendEmail()更改为

if(mail ($this->to,$this->subject,$this->message,$this->header)) {

我可能会遗漏你想要达到的目标,如果我在这里偏离轨道,请告诉我。