Edward Posted July 4, 2007 Share Posted July 4, 2007 Hi, I'm using two pages, one with a form and the $email_content variable which (in the full version) can be edited by the site visitor, the other page to send an html email containing the $email_contact variable. Can anyone see the best way to do this in terms of using the appropriate functions? I'm using htmlentities on the first page and stripslashes but it's not working properly, I may be on the wrong track? I've experimented but either the email doesn't sent, or it excludes the variable, or it has slashes in the email which affect it visually. index.php: <?php if (isset($_POST['submit_send_short_list'])) { include('test_email.php'); } else { // IF NOT SUBMITTED $email_content .= '<tr>'; $email_content .= '<td width="10" align="left" valign="top" cellpadding="0" cellspacing="0" border="0"></td>'; $email_content .= '<td width="120" height="170" align="center" valign="middle" cellpadding="0" cellspacing="0" border="0">'; $email_content .= '<a href="http://www.accentbank.co.uk/index2.php?page=02_search®ion=east_anglia&actor=will_findley&short_list_actor_east_anglia_will_findley=TRUE">'; $email_content .= '<img src="http://www.accentbank.co.uk/page_02_search_actors/east_anglia/will_findley_small.jpg" width="120" height="160" alt="" border="0" />'; $email_content .= '</a></td>'; $email_content .= '<td width="10" align="left" valign="top" cellpadding="0" cellspacing="0" border="0"></td>'; $email_content .= '<td width="650" align="left" valign="top" cellpadding="0" cellspacing="0" border="0">'; $email_content .= '<p><a href="http://www.accentbank.co.uk/index2.php?page=02_search®ion=east_anglia&actor=will_findley&short_list_actor_east_anglia_will_findley=TRUE">Will Findley</a><br />Norwich, Norfolk</p></td>'; $email_content .= '<td width="10" align="left" valign="top" cellpadding="0" cellspacing="0" border="0"></td></tr>'; $email_content = htmlentities($email_content); // YES echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo '<p>'; echo '<input type="text" name="recipient" value="'.$_POST['recipient'].'" size="20" maxlength="100" /><br />'; echo '<input type="hidden" name="email_content" value="'.$email_content.'" />'; echo '<input type="submit" name="submit_send_short_list" value="e-mail short list" />'; echo '</p>'; echo '</form>'; } ?> test_email.php: $email_content = $_POST['email_content']; // remove slashes $email_content = stripslashes($email_content); // remove slashes $subject = 'A Short List from AccentBank.co.uk'; $body = "<html><head> </head> <body> <table width=\"100%\" height=\"\" align=\"center\" valign=\"top\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"> <tr> <td width=\"10\" align=\"left\" valign=\"top\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"></td> <td width=\"800\" align=\"left\" valign=\"top\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" colspan=\"3\"> <p> <p><img src=\"http://www.accentbank.co.uk/email_short_list/img_logo_99x99.gif\" width=\"99\" height=\"99\" alt=\"Accent Bank\" border=\"0\" /></p> <p>www.accentbank.co.uk | <a href=\"mailto:[email protected]\">[email protected]</a></p> The following short list of actors has been sent to you by someone browsing AccentBank.co.uk</p> </td> <td width=\"10\" align=\"left\" valign=\"top\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"></td> </tr>".$email_content."</table> </body> </html>"; $fromname = "Accent Bank"; // site owner $fromemail = "[email protected]"; // site owner $headers = "From: $fromname <$fromemail>\r\n"; // $headers .= "Reply-To: $fromname <$fromemail>\r\n"; // 2 $headers .= "Return-Path: $fromname <$fromemail>\r\n"; // 3 $headers .= "MIME-Version: 1.0\r\n"; // 4 $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; // 5 $headers .= "X-Priority: 3\r\n"; // 4th: 1 or 3? $headers .= "X-MSMail-Priority: Normal\r\n"; // 5th: Normal or High? $headers .= "X-Mailer: php\r\n"; if (mail($_POST['recipient'], $subject, $body, $headers)) { echo '<p>Thank you '.$_POST['recipient'].', your short list has been sent!</p>'; } Link to comment https://forums.phpfreaks.com/topic/58456-problem-sending-mail-with-variables-in-maybe-due-to-slashes/ Share on other sites More sharing options...
Yesideez Posted July 4, 2007 Share Posted July 4, 2007 That first script you can make it a lot easier by doing something like this: <?php $email_content='<html> <body> <table border="1"> <tr><td>Hellow</td><td>Example</td></tr> </table> </body> </html>'; ?> Link to comment https://forums.phpfreaks.com/topic/58456-problem-sending-mail-with-variables-in-maybe-due-to-slashes/#findComment-289881 Share on other sites More sharing options...
Yesideez Posted July 4, 2007 Share Posted July 4, 2007 If you want to send an email as HTML a good way to start is write the HTML as a separate file and test it so you get it working as you like it. Then, copy and paste it into your PHP script and wherever yuo want variables to appear, add them in. Link to comment https://forums.phpfreaks.com/topic/58456-problem-sending-mail-with-variables-in-maybe-due-to-slashes/#findComment-289885 Share on other sites More sharing options...
Edward Posted July 4, 2007 Author Share Posted July 4, 2007 I've tried it with simpler html blocks, which is why I broke the lines up in the first script. I'm pretty sure the HTML is fine. What I need to know is what do I need to do to a variable containing html and double quotes before placing it inside a hidden form text field (to be sent via POST), and what do I need to do it after it's been sent via POST before I send it in a email, eg add slasshes, remove them, use htmlentities etc... Link to comment https://forums.phpfreaks.com/topic/58456-problem-sending-mail-with-variables-in-maybe-due-to-slashes/#findComment-289938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.