Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Web Page through Email in php

Tags:

php

email

as in asp we have function to send complete web page in email, which basically save lot of time for developer in creating & sending email

see the following code

     <%
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From="[email protected]"
    myMail.To="[email protected]"
    myMail.CreateMHTMLBody "mywebpage.html",cdoSuppressNone
    myMail.Send
    set myMail=nothing
    %>

as we know that CreateMHTMLBody will get data from mywebpage.html and send it as a body of email.

i want to know does any function like (CreateMHTMLBody) this is available in php ?

if Not can we crate any function if yes, please give me some hints.

Thanks

like image 676
air Avatar asked Dec 03 '22 13:12

air


2 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
    }
?>
like image 114
MetaCipher Avatar answered Dec 26 '22 00:12

MetaCipher


To add to Erik's answer, if you want to import a local (or remote!) file instead of specifying the HTML in the code itself, you can do this:

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

// fetch remotely
$message = file_get_contents('http://example.com/filename.html');
like image 40
ceejayoz Avatar answered Dec 26 '22 01:12

ceejayoz