Send email with a template using php

后端 未结 9 2185
南旧
南旧 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:15

    First, you have to make a HTML template:

    Name:
    Email:

    Below code is the mailing code that uses the template.

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $name=$_REQUEST['name'];
        $email=$_REQUEST['email'];
        $to=$email; //change to ur mail address
        $subject="UandBlog - Send Email Template Demo";
        $message =  file_get_contents('Your template path'); // Your Template        
        $headers = 'MIME-Version: 1.0'."\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
        $headers .= "From: noreply@uandblog.com"; 
    
        mail($to, $subject, $message, $headers); 
    }
    

    You can also download the full code with the template from UandAblog.

提交回复
热议问题