-1

这是我的代码

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。我怎么能通过标题做到这一点?

谢谢

4

1 回答 1

0

你必须通过标题来做吗?

为什么不创建一个新变量

用于 html 邮件

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

或纯文本

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

然后将您的更改sendEmail()

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

我可能错过了您想要实现的目标,如果我在这里偏离轨道,请告诉我。

于 2013-11-08T10:26:18.577 回答