Jump to content

php help needed


kev wood

Recommended Posts

i need to know if it is possible to send a php page using php as an email newsletter?

 

i know it is possible to send an html page as a newsletter but i need to know if i can send a page which has mysql on it as a newsletter.  i have tried a few different methods (get file contents, fopen, fwrite, fread) and none have has the desired effect.  i can get the page to be emailed to the mailing list but the actual email has nothing held in it (just sends blank email).

 

does anyone know of a way this can be done or if i have got my code wrong.  I can post my code if you need to look at it to see what i mean more clearly.

 

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/
Share on other sites

No, a php page is rendered by the php engine on every page view. This is impossible to do currently via email, though there are some clever ways to emulate this (using images for content, for example). In the end though, you will not be able to change any code in the email once it is sent.

 

A static html page built by a php script is still a static html page.

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516660
Share on other sites

discomatt

 

i want to convert the page before the email is sent so that the images from the database are embedded into the content of the page.  the problem i having at the minute is that any dynamically generated parts of the page are not being sent in the email.

 

i know it is possible to sent a html page using php as an email but the page i want to send has images stored on it which are recalled from a database on the server.

 

so i need to know if you can convert the page and then send it out as an email.

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516667
Share on other sites

how would i send a page which has mysql on it to recall images from a db as an email.  i have tried the a few ways but always end up with a blank email being sent.  the closest i have got to the content being sent is the headers and the text but the images were not sent.

 

the code i used for this was:-

 

$message .= implode("",file("broad_prev.php"));

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516681
Share on other sites

I think you're in a little over your head here. Most of what you said makes no sense. I think you need to start by learning the fundamentals of HTML, PHP and MySQL, and learn step-by-step what each do, and how you can use them to solve your problem.

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516685
Share on other sites

I think you're problem could be that you are sending a plain text email.

 

HTML emails require extra coding to be interpreted correctly.

 

Check this link from sitepoint and make sure you're doing everything correctly.

 

http://www.sitepoint.com/article/advanced-email-php/

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516690
Share on other sites

i am not over my head since i have a 2:1 degree in web page design.  i am stuck working this problem out and since this is a forum i thought people who have done this a lot longer than me would be able to point me in the right direction.

 

i have created a emailing broadcast system which works in full the only thing which i was not TAUGHT which i am stuck on is displaying images from a remote server database in a email newsletter which is emailed out to the email list.  i know how to use php and mysql to transfer data and display information and i also have a good understanding of a lot of other languages used in the world of web development.

 

which part makes no sense?????

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516696
Share on other sites

All you need do is get the page into a string, then send this string as an html email.

 

<?php

  ob_start();
  include "yourphpfile.php";
  $html = ob_get_contents();
  ob_end_clean();

  // now $html contains the outputted html of your yourphpfile.php

?>

 

If your having problems displaying images this way, you will need to check the html source to make sure they have full file paths to your server.

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516702
Share on other sites

poleposters

 

thanks for the link but that is a bit to basic for what i need it to do.  i already new how to send plain text or plain html emails using php i got stuck with the sending images from a db along with the email (in with the text).  thanks anyway tho the site will come in handy i am sure.

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516738
Share on other sites

poleposters

 

thanks for the link but that is a bit to basic for what i need it to do.  i already new how to send plain text or plain html emails using php i got stuck with the sending images from a db along with the email (in with the text).  thanks anyway tho the site will come in handy i am sure.

 

I think your missing the point. Images are not embedded into html, you simply display the path to the image within a img tag.

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516805
Share on other sites

If you read the article through you'll work out that you can send a plain text email or a HTML email.

 

You want to include images so you will need to send a HTML email containing the <img> tag.

 

Then what you want to do is create the <img> tag dynamically.

 

So first you would query the database to select the desired images based on you your selection preferences.

 

ie SELECT image FROM table Where this=that

 

Then You can place your results in a variable for a single image or an array for multiple images.

 

$image=pics/imageone.jpg or $image[0]=pics/imageone.jpg etc.

 

Then when you create your HTML email place variable/array appropriately in the img tag of the email body.

 

ie

 

$body=<html><img src="$image"></html>

 

Then the email gets sent to the recipient. They see the images in their email. But the image is always hosted on your server.Never embedded in the email.(However the article explains how to attach a file/image to your email)

 

This brings another important consideration . Do you have the absolute location of the image stored in your database or the relative.

 

ie http://www.yoursite.com/pics/imageone.jpg or  just pics/imageone.jpg

 

If its the relative URL you will need to add the server location before the image location.

 

 

Link to comment
https://forums.phpfreaks.com/topic/101042-php-help-needed/#findComment-516893
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.