0

I've been using PHPMailer successfully for a couple of years. I just refreshed my PHPMailer class from their github site, and now my server throws 500 errors. I tracked down the problem to this line (simplified for this post):

$mail->Body = "<p>Hello World</p>";

All of the example that I see on the worxware website these days show the body of the email being read from a file like this:

$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);

I also tried modifying my code to use the MsgHTML syntax, but I still have the same result:

$body = "<p>Hello World</p>";
$mail->MsgHTML($body);

I can't imagine that it matters whether this body gets populated from a file or from a local variable, but nothing that I try works. What am I missing? Thanks!

AndroidDev
  • 20,466
  • 42
  • 148
  • 239
  • Hello Kindly refer this link it will help you http://stackoverflow.com/questions/7706918/eregi-replace-data-what-does-this-line-do – kailash sharma Mar 30 '15 at 17:12
  • Thank you. I tried that, but I still get the same result. I'll update my post to show it. – AndroidDev Mar 30 '15 at 17:17
  • None of the examples on github use `eregi_*` functions - they have been deprecated for years, so I don't know where you got that from. Why are you even doing that anyway? PHPMailer doesn't care where you get your content from, so long as it ends up in `Body`. – Synchro Mar 30 '15 at 18:26
  • @Synchro - I was referring to examples found here: http://phpmailer.worxware.com/index.php?pg=examplebsmtp. Maybe they aren't 'official' examples? I thought that they were. My mistake, and my apologies. – AndroidDev Mar 30 '15 at 19:27
  • That site's not been updated for a long time - It's never actually lived there (it was on SourceForge, then Google Code, then Github). Everything is now on Github, though there are a zillion other sites that say lots of random (often wrong!) stuff about PHPMailer! – Synchro Mar 30 '15 at 19:35
  • Good to know. Unfortunately, if I Google 'phpmailer example', my first four results are from that site. – AndroidDev Mar 30 '15 at 19:38

1 Answers1

1

$output = str_replace(array("\n","\r"),"",$output);

try this

kailash sharma
  • 356
  • 1
  • 12
  • That worked. I wonder why that wasn't anywhere in any of their examples. Oh well. Thanks! – AndroidDev Mar 30 '15 at 17:30
  • It's not in the examples because that's a pretty strange thing to do - most people want line breaks in their messages! – Synchro Mar 30 '15 at 18:27
  • It turns out that this isn't the solution to my issue. I'm getting very eratic results no matter what I do. Some attempts work, some don't, and I still can't figure out what makes any differences. To make sure that nobody else is mislead thinking that this is what they should do, I need to retract my acceptance of this answer. Sorry about that @kailash. – AndroidDev Mar 30 '15 at 19:23
  • @Synchro - you are right. I was very surprised that this 'worked'. It turns out that it really didn't. Just a coincidence masking something else. Sorry for the confusion. – AndroidDev Mar 30 '15 at 19:25