Jump to content

Email HTML page.


Bradillac

Recommended Posts

This is my first post, so I feel obligated to give a little background.  To make it short, basically I used to be an ASP developer and now I've jumped head first into PHP.  The transition has been nothing but positive so far and I'm amazed at how many things transfer over.

I do have one problem however.  In ASP it's possible to, when sending an email with a script, link the script to another page.  So basically the script takes from the server all the images and the html from that page and puts them in the email.  So if I were to link it to a PHP page it would send the html version of it.  Basically it's an easy way to make newsletters. The code looks something like this:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.CreateMHTMLBody "http://www.w3schools.com/asp/"
myMail.Send
set myMail=nothing
%>

I haven't found any scripts that do this similarly in PHP so.. I thought I'd come and exploit the friendly community here.  Sorry to exploit you guys but, I know people here know what they're talking about...
Link to comment
Share on other sites

First, Welcome to PHP
U will never think of using another Micro N Soft language again
try this

[code]
<?php
$to = $email;
$subject = "Email Subject";

$body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n"

."<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
."<head>\n"
."<title>The Title</title>\n"
."</head>\n"
".your message<br />\n"
."Your Message\n"
."</body>\n"
."</html>\n";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$name.' <'.$email.'>,' . "\r\n"; //This is the TO name and Email
$headers .= 'From: Name<email@domain.tld>' . "\r\n"; // This is YOUR name and email

if(mail($to, $subject, $body, $headers)){
echo "Mail has been sent";
}else{
echo "Mail Failed";
}

?>
[/code]
Link to comment
Share on other sites

That sends an HTML email all right.  But the structure of what I'm trying to do goes like this:

Send a form.  That form adds all it's information to a database.  There is a page (we'll call it newsletter.php) on the server that changes depending on the values stored in that database.  After updating the form I need to send newsletter.php as html with all its images attached. 

The attached images part isn't as necessary because I can code the page to link to all images using full urls. 
Link to comment
Share on other sites

  • 2 years later...
I have a similar situation in that there's a PHP/HTML script which I want to be the body of the email. The previous poster didn't answer the question at all and I can't find the solution anywhere online. It's easy to do in Cold Fusion and ASP (and maybe others) so there should a way of doing it in PHP.

Anyone got any ideas?

Thanks.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.