cyberRobot Posted March 8, 2011 Share Posted March 8, 2011 No problem, I would have done that earlier but I get a little lazy. I wish there was a way to copy & paste code from the forum without having to add all the line breaks back in. If anyone knows of a way, I'm all ears. Link to comment Share on other sites More sharing options...
MatthewJ Posted March 8, 2011 Share Posted March 8, 2011 I think it depends on what editor you are using... I write most of my code in Dreamweaver or notepad++ and both seem to keep formatting when I paste them here. Link to comment Share on other sites More sharing options...
cyberRobot Posted March 8, 2011 Share Posted March 8, 2011 I think it depends on what editor you are using... I write most of my code in Dreamweaver or notepad++ and both seem to keep formatting when I paste them here. When I copy from Dreamweaver and paste to the forum, it keeps the formatting. But when I copy from the forum and paste into Dreamweaver, all the linebreaks disappear. I've also tried regular Notepad. I haven't tried Notepad++ though... Link to comment Share on other sites More sharing options...
cyberRobot Posted March 8, 2011 Share Posted March 8, 2011 Out of curiosity I tried WordPad and apparently that works. From there, I can post into Dreamweaver and the linebreaks don't disappear. Link to comment Share on other sites More sharing options...
JulianWill Posted March 8, 2011 Author Share Posted March 8, 2011 I just tried it with word 2010 and it works fine. Thanks for the tip. Will certainly help me save time in the future. Regards Link to comment Share on other sites More sharing options...
JulianWill Posted July 13, 2017 Author Share Posted July 13, 2017 I appreciate this post is over 6 years old now however i have come up with the same issue again with the following script. It shows the mail as coming from the server address and not the users email address. I have tried adding $headers in lots of different locations but I still cannot get it to work. Any assistance would be greatly appreciated. Heres the code: <?php // your email $user_email = "**************.co.uk"; $headers = "From: " . strip_tags($_POST['cf-email']); $mail = array( "name" => htmlspecialchars($_POST['cf-name']), "email" => htmlspecialchars($_POST['cf-email']), "subject" => htmlspecialchars($_POST['cf-subject']), "message" => htmlspecialchars($_POST['cf-message']), ); function validate($arr){ return !empty($arr['name']) && strlen($arr['message']) > 20 && filter_var($arr['email'],FILTER_VALIDATE_EMAIL); } if(validate($mail)){ echo mail($user_email, $mail['subject'], "Name : {$mail['name']}\n" ."E-mail : {$mail['email']}\n" ."Message : {$mail['message']}" ); } ?> Link to comment Share on other sites More sharing options...
Jacques1 Posted July 13, 2017 Share Posted July 13, 2017 PHPMailer Link to comment Share on other sites More sharing options...
requinix Posted July 13, 2017 Share Posted July 13, 2017 In your other script you were successfully(ish) using $headers to set a From: address. You aren't doing that here. Try it. Link to comment Share on other sites More sharing options...
JulianWill Posted July 13, 2017 Author Share Posted July 13, 2017 The mail is sending successfully however the server address is showing and not the senders email address (as before). I have been trying to figure it out for two days now . Hence my post here. I will keep trying, but it is driving me crazy Link to comment Share on other sites More sharing options...
requinix Posted July 13, 2017 Share Posted July 13, 2017 Try reading what I said. Link to comment Share on other sites More sharing options...
JulianWill Posted July 13, 2017 Author Share Posted July 13, 2017 Ha ha okay. I am assuming that somewhere in this piece of code I need to put $headers: if(validate($mail)){ echo mail($user_email, $mail['subject'], "Name : {$mail['name']}\n" ."E-mail : {$mail['email']}\n" ."Message : {$mail['message']}" ); Would I be correct? Link to comment Share on other sites More sharing options...
Jacques1 Posted July 14, 2017 Share Posted July 14, 2017 So you've dug out your thread after 6 years, but you cannot be bothered to read your own code in this exact thread? Anyway, none of this matters, because the code is wrong on every single level. You have header injection vulnerabilities all over the place, you're forging the From header, you're using completely wrong functions. Why on earth would you try to strip HTML tags from an e-mail header? What is HTML-escaping supposed to do with a plaintext message? If any of this "worked" in the last 6 years, you have been very, very lucky -- or you just haven't noticed the problems. Stop messing with low-level functions like mail() and at least try to understand what the code you're writing/copypasting actually does. You need a high-level mail library like the already mentioned PhpMailer. Forget about trying to assemble the raw message yourself. It will fail and produce all kind of defects and security vulnerabilities. The From address must be your address. You cannot just pretend that the mails you're sending from your server come from the user. Forged headers are a common spammer tactic, and many systems deliver those e-mails straight to the spam folder. Or even reject them altogether. You need to apply the right functions to each specfic context. An e-mail header is not HTML. Plaintext is not HTML. Those are all entirely different contexts with entirely different syntax rules. Mail headers are handled by PhpMailer. Plaintext is plaintext -- there's nothing to escape. Link to comment Share on other sites More sharing options...
JulianWill Posted July 14, 2017 Author Share Posted July 14, 2017 Jacques Thank you for your message. I would firstly like to apologise for not being as knowledgeable on the subject as you clearly are. I am trying to learn, and the help I was afforded on here six years ago was superb. Clearly things have changed. The code is not my code however it was the code that was provided to me within a very expensive template that I have purchased. I have now resolved the issue and the form is working fine. Sorry to have bothered you. Link to comment Share on other sites More sharing options...
Jacques1 Posted July 14, 2017 Share Posted July 14, 2017 “Knowledgeable on the subject”? What are you talking about? Your job was to look at this line of your old code: mail($your_email, $email_subject, $email_content, $headers) and then figure out where the $headers go. That was – literally – the only thing you had to do. This doesn't require PHP knowledge. You don't have to be a programmer. You probably don't even have to be able to read. This is pattern recognication at the most basic level. Trained monkeys do it. And you're saying you couldn't? Anyway, if you paid money for the code, then you've been ripped off. The code is not only amateur-level at best, it's harmful. Demand a refund. Link to comment Share on other sites More sharing options...
JulianWill Posted July 14, 2017 Author Share Posted July 14, 2017 I am clearly an untrained monkey then. Enjoy your day. Link to comment Share on other sites More sharing options...
Jacques1 Posted July 14, 2017 Share Posted July 14, 2017 (edited) No. I think you're just very, very lazy. And that's not the good kind of laziness which makes you look for smart solutions to avoid extra work. It's the laziness where you just shut down your brain and wait for somebody else to tell you what to do. Edited July 14, 2017 by Jacques1 Link to comment Share on other sites More sharing options...
cyberRobot Posted July 14, 2017 Share Posted July 14, 2017 (edited) Since the topic appears to be devolving and the issue is said to be resolved, I'm locking the topic. @JulianWill - If you need anything else, please don't hesitate to start a new topic. Edited July 14, 2017 by cyberRobot Link to comment Share on other sites More sharing options...
Recommended Posts