Email webpage in php

as in asp, we have the function of sending a full web page by email, which basically saves a lot of time for the developer when creating and sending email

see the following code

     <%
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From="xxx@example.com"
    myMail.To="xxx@example.com"
    myMail.CreateMHTMLBody "mywebpage.html",cdoSuppressNone
    myMail.Send
    set myMail=nothing
    %>

since we know that CreateMHTMLBody will receive data from mywebpage.html and send it as an email.

I want to know which function (CreateMHTMLBody) is available in php?

If we can not display any function, if so, please give me some advice.

thank

+3
source share
4 answers

Example below:

<?
    if(($Content = file_get_contents("somefile.html")) === false) {
        $Content = "";
    }

    $Headers  = "MIME-Version: 1.0\n";
    $Headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $Headers .= "From: ".$FromName." <".$FromEmail.">\n";
    $Headers .= "Reply-To: ".$ReplyTo."\n";
    $Headers .= "X-Sender: <".$FromEmail.">\n";
    $Headers .= "X-Mailer: PHP\n"; 
    $Headers .= "X-Priority: 1\n"; 
    $Headers .= "Return-Path: <".$FromEmail.">\n";  

    if(mail($ToEmail, $Subject, $Content, $Headers) == false) {
        //Error
    }
?>
+6
source

Erik , ( !) HTML , :

// fetch locally
$message = file_get_contents('filename.html');

// fetch remotely
$message = file_get_contents('http://example.com/filename.html');
+3

PHP -. :

// Start output buffering
ob_start();

// Get desired webpage
include "webpage.php";

// Store output data in variable for later use
$data = ob_get_contents();

// Clean buffer if you want to continue to output some more code
// in which case it would make sense to use this functionality in the very beginning
// of your page when no other code has been processed yet.
ob_end_clean();
+3
source

Here's how:

$to  = 'joe@example.com';
$subject = 'A test email!';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Put your HTML here
$message = '<html><body>hello world</body></html>';

// Mail it
mail($to, $subject, $message, $headers);

You have just sent an HTML email address. To load an external HTML file, replace $ message = '' with:

$message = file_get_contents('the_file.html');
+1
source

Source: https://habr.com/ru/post/1726983/


All Articles