can this be used to email a php page to a mailing list using a submit button?

You can use php's mail function..

the page was set up so it uses the mail() function but it does not like the mysql in the code when the page is being created it just keeps throwing up errors.

the code that was originally created looks like this

<?php
// construct mailing list array
$merc_list = explode(",",$merc_mailingList);

// deploy the emails
for($i=0; $i<count($merc_list); $i++){
$message = "<style type=\"text/css\">body {	margin: 0;	background: ;	background-image: url();	background-repeat: no-repeat;
} .mainTxt {font-size: 11px; color:#444444; font-family: Arial, Helvetica, sans;} .whiteTxt {font-size: 9px; color:#FFFFFF; font-family: Arial, Helvetica, sans;} a:link {color:#EB7324} ul {font-size: 9px; color:#EB7324;padding-left: 5px;}
.style3 {font-family: Geneva, Arial, Helvetica, sans-serif; color: #FFFFFF; font-weight: bold; }
.style1 {font-family: Arial, Helvetica, sans-serif;	font-size: 10px;color: #666666;}
</style>";

	$message .= "<body leftmargin=\"0\" topmargin=\"0\">
<table width=\"900\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"5\">
    <tr>
        <td height=\"95\" colspan=\"2\" scope=\"col\"><img src=http://acmeart.co.uk/mercury/layout/BroadsheetSample/broadhead.jpg width=\"900\" height=\"150\" /></td>
    </tr>
    <tr>
        <td height=\"25\" colspan=\"2\" scope=\"col\"><span class=\"mainTxt\"><strong>$broad_topictitle1</strong></span></td>
    </tr>
    <tr>
        <th width=\"23%\" height=\"200\" scope=\"col\"><div align=\"left\">
					<?php
											
					$query = "SELECT broad1 FROM images_broad";
					$result=mysql_query($query);

					while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
					echo '<img src="'.$row['broad1'].'"/>';
					}
						      
					?>
		<p>&nbsp;</p></div></th>
        <td width=\"77%\" scope=\"col\"><table width=\"99%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
            <tr>
                <td align=\"left\" valign=\"top\"><span class=\"mainTxt\">$broad_messagebody1</span></td>
                <!-- End Image 1 -->
            </tr>
        </table>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p></td>
    </tr>
    <tr>
        <td height=\"28\" colspan=\"2\" scope=\"col\"><span class=\"mainTxt\"><strong>$broad_topictitle2</strong></span></td>
    </tr>
    <tr>
        <th height=\"95\" scope=\"col\"><div align=\"left\"><img src=\"http://acmeart.co.uk/mercury/layout/BroadsheetSample/broad2.jpg\" width=\"200\" height=\"200\" /><p>&nbsp;</p></div></th>
        <td scope=\"col\"><table width=\"99%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
                <tr>
                    <td align=\"left\" valign=\"top\"><span class=\"mainTxt\">$broad_messagebody2</span></td>
                    <!-- End Image 1 -->
                </tr>
            </table>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p></td>
    </tr>
    <tr>
        <td colspan=\"2\" scope=\"col\"><img src=\"http://acmeart.co.uk/mercury/layout/BroadsheetSample/broadfoot.jpg\" width=\"900\" height=\"150\" /></td>
    </tr>
    
    <tr>
        <td height=\"13\" colspan=\"2\" scope=\"col\"><div align=\"justify\"><span class=\"style1\">Linacre Voice is a monthly bulletin from LinacreOne Community Partnership 140-142 Linacre Road Litherland L21 8JU Tel: (0151) 922 4898 Open Monday - Thursday 10:00am - 4:00pm <font size=\"1\"></font></span> </div></td>
    </tr>
</table>
</table>
</body>";


	
	// Contacts
	$replyName = "$merc_replyId";
	$replyEmail = "$merc_replyAddress";

	$contactname = "";
	$contactemail = "$merc_list[$i]";

	// Subject
	$subject = "$merc_messageTitle";

	// Headers
	$headers = "MIME-Version: 1.0\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
	$headers .= "From: ".$replyName." <".$replyEmail.">\r\n";
	$headers .= "To: ".$contactname." <".$contactemail.">\r\n";

	mail($contactemail, $subject, $message, $headers);
	} // END for

?>

i was playing about with this before to see if i could get it to load the page without it being coded again to get round the mysql problem. with the code like this it will not display the images and the code dies when it gets to the mysql.

this is another page which was already meant to be set up according to the lad who was working on it before me.

You can't have

                <?php

                $query = "SELECT broad1 FROM images_broad";
                $result=mysql_query($query);

                while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
                echo '<img src="'.$row['broad1'].'"/>';
                }

                ?>

in $message. Since it is already a php variable. Assign only the <img src value to $message. Then try again. That will surely fix one of your problems.

the $message variable is set to be the information that is sent out so before this is set could i set more variables to be the images and then set the image source to be these variables would that get round the problem of having the mysql inside the code for the message variable.

would the code for this be something like

$image1 = <?php
											
$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);

while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
echo '<img src="'.$row['broad1'].'"/>';
}
						      
?>

and then use the $image1

instead of having the echo at the bottom of the mysql query should i try to set the result from the query to a variable and then recall this variable in the image tag.

Instead, assign it to $message.
$message.="<img src=$row>";

the code i have got for the database connection looks like this and it is placed before the body tag in the php page so that it has no effect on what it being displayed on the page

$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);

while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
$message.= '<img src="'.$row['broad1'].'"/>';

when the variable l $message has been set to equal the image from the database would it be displayed in the image tag in the body of the message like this

<img src=\"$message\" />

I didn't get you.. What I said was,
concat <img src='row1> to $message. So, it will be like,
$message.=$row1;
then again,

$message.=<p>&nbsp;</p></div></th>
        <td width=\"77%\" scope=\"col\"><table width=\"99%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
            <tr> //.... and so on

instead of putting the code in for the message is there not a way to just recall the page which already has the images inserted into it from the database. the page is created when the user goes to the preview page.

i was trying to work this out using an i frame but when it went to the page where it tells the user the message was sent it was displaying the preview page over the top of that page and the email was blank.

if that could be done it would save duplicating the code to produce the same page twice and if it can be done it would save the hassle of trying to insert images into the code for the message as it clearly does not want mysql code in that section of the code.

I didn't get you.. What I said was,
concat <img src='row1> to $message. So, it will be like,
$message.=$row1;
then again,

$message.=<p>&nbsp;</p></div></th>
        <td width=\"77%\" scope=\"col\"><table width=\"99%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
            <tr> //.... and so on

would this not just send the image as the message and not put any of the text to go with it.

also there will be more than one image to be placed on this page, that is why i was asking if it would be possible to assign the data from the db to their own variables.

the page that will be emailed out will have a title section with an image and some body text and underneath that there will be the same again with different titles images and text.

Yep. Thats possible. Write the images to a page. Send the mail with attachments.

would this not just send the image as the message and not put any of the text to go with it.

No. Since you are concating previous value of $message with the images, the text along with images will be sent.

the last line of mysql query now looks like this $message.= '<img src="'.$row['broad1'].'"/>'; i think that is how you wanted me to put it. it is now giving me an error when i try to load the page saying unexpected $ at the end of the code but this must have something to do with the $message=. within the html code.

can the mail function only send pure html with no php inside the message body. if that is the case could something like $message=<a href="broad_prev.php"></a> work to get the page to display once the email has been sent.

i think that is how you wanted me to put it. it is now giving me an error when i try to load the page saying unexpected $ at the end of the code but this must have something to do with the $message=. within the html code.

No.. there is an unclosed bracket.. Find it and close it !

on looking into it the a href would probably not work but is it possible to set the subject of the message to be a php page as this way the php will not have to be put into the message body an it should not throw up any errors (if it works).

the $subject variable i used for the message title so this is not going to work either. i ahve just been looking at some code which uses a textarea for the body of the message can this be edited so that the text area contains the preview page.

i have just been looking more at the example that uses the textarea and to get the body of the message imported into the email it uses this $message = $_REQUEST["body"]; could this line of ode be modified so that instread of the body in the request it would look something like this $message = $_REQUEST["broad_prev.php"]; can the $_request variable be used to recall a page instead of an textarea?

Why not write a new script ? You can check this example here to send mails with attachments.
http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

this would send the newsletter as an attachment would it not?

i would be happy to do it this way but i do not have the final say on how the email will look and the boss wants the email to be the message without attachments.

can the $_request variable be used to recall a page instead of an textarea?

Nope.. You can only use $_REQUEST to get the value from a form.
Umm.. I think you can try, $message = implode("",file("broad_prev.php")); Not sure, but you can try that.

it worth giving it a go not much else has seemed to work up to now.

that has done better than the rest. it has tried to send the mail but only the very last line was showing up on the email. none of the images or text has come through with it.

where the php is on the page being sent it has just sent the closing tags and not the actual image that is being recalled from the db on that page.

this looks like the way forward for now i will research into this over the weekend and see what i can come up with. thanks once again for you help.

hmm.. All the best !

i have just been looking more at the example that uses the textarea and to get the body of the message imported into the email it uses this $message = $_REQUEST["body"]; could this line of ode be modified so that instread of the body in the request it would look something like this $message = $_REQUEST["broad_prev.php"]; can the $_request variable be used to recall a page instead of an textarea?

That will not work, unless you are posting a variable called 'broad_prev.php'

If you want $message to contain that pages content... use this: $message = fopen("http://www.yoursite.com/broad_prev.php", "r");

i have looked at the fopen function over the weekend and i thought that the get file_get_contents function would work better than the fopen.

the code i am using now looks like this $message = file_get_contents ('my website'); but on the email that is sent out it has no content held within it.

do i need to use the fopen, fread, or fwrite functions to get it to display the contents of the page. the page that i am trying to display uses nysql to retrieve images from a database and places them on to the page.

i have a line of code at the bottom which states what should be sent with the message which looks like this mail($contactemail, $subject, $message, $headers); should the variable message be set to the contents of the page and therefore be displayed in the message body.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.