senyo Posted November 10, 2009 Share Posted November 10, 2009 I found this script for sending emails, it works but if the email has <img src="image.jpg"/> it will send this <img src="image.jpg"> < I tried to replace < > < with the right characters but it doesn't work. Any suggestions? <?php /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */ $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $slashes= stripslashes($message); /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */ if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) { echo "<h4>Invalid email address</h4>"; echo "<a href='javascript:history.back(1);'>Back</a>"; } elseif ($subject == "") { echo "<h4>No subject</h4>"; echo "<a href='javascript:history.back(1);'>Back</a>"; } /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */ elseif (mail($email,$subject,$slashes)) { echo "<h4>Thank you for sending email</h4>"; } else { echo "<h4>Can't send email to $email</h4>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/ Share on other sites More sharing options...
ToonMariner Posted November 10, 2009 Share Posted November 10, 2009 html_entity_decode is your 'friend' in this instance - notwithstanding any detrimental effects Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-954722 Share on other sites More sharing options...
senyo Posted November 10, 2009 Author Share Posted November 10, 2009 I tried and the output is the same $a = htmlentities($slashes); $b = html_entity_decode($a); Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-954744 Share on other sites More sharing options...
Adam Posted November 10, 2009 Share Posted November 10, 2009 I tried and the output is the same $a = htmlentities($slashes); $b = html_entity_decode($a); That's because applying htmlentities to a string like: <img src="image.jpg"> Would give you: <img src="image.jpg"> When you're using html_entity_decode() you're just reverting it back. Remove "htmlentities($slashes);" .. Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-954749 Share on other sites More sharing options...
senyo Posted November 10, 2009 Author Share Posted November 10, 2009 I get the same result, I don't know what is the problem in the email it shows the text <img src="image.jpg"/> not the image, in the page source it shows this <img src="image.jpg"> < Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-954757 Share on other sites More sharing options...
senyo Posted November 10, 2009 Author Share Posted November 10, 2009 I think that the text format is the problem Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-955041 Share on other sites More sharing options...
senyo Posted November 10, 2009 Author Share Posted November 10, 2009 I think that is a problem with the script, it doesn't send the whole text Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-955052 Share on other sites More sharing options...
senyo Posted November 10, 2009 Author Share Posted November 10, 2009 the script sends all the text, so I think that the problem is the encoding, or something that I don't know $rezult=mb_convert_encoding($data,"HTML-ENTITIES","utf-8"); Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-955239 Share on other sites More sharing options...
mikesta707 Posted November 10, 2009 Share Posted November 10, 2009 just tried it and it works for me. try removing addslashes Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-955245 Share on other sites More sharing options...
senyo Posted November 10, 2009 Author Share Posted November 10, 2009 It work, so is not my fault, the server interprets the code like this Quote Link to comment https://forums.phpfreaks.com/topic/180956-images-in-email-problem/#findComment-955251 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.