Send email with a template using php

后端 未结 9 2159
南旧
南旧 2020-12-04 07:45

How can I send an email using php then add a template design in the email? I\'m using this:

$to = \"someone@example.com\";  
$subject = \"Test mail\";  
$mes         


        
9条回答
  •  情深已故
    2020-12-04 08:20

    If you are using phpmailer then try this on

    // Content
    $mail->isHTML(true); 
    $mail->Subject = 'Newsletter Mail';
    $mail->Body = file_get_contents('mail.html');
    if (!$mail->send()) {
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }
    

    And if you are using php mail then just need to add

    $body= file_get_contents('mail.html');
    $headers = 'MIME-Version: 1.0'."\r\n";
    $header.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
    $header .="From:\r\n";
    

    And if you are using CI(Codeigniter) then in my case I'm created mail helper of ci but rest work same

    $message = $this->load->view('front/invoice_email',$data, TRUE); //"Hi, 9999999999 \r\n".";
    if(!empty($adminEmail)) {
      send_user_mail($adminEmail, $message, $subject);
    }
    

提交回复
热议问题