0

On my WordPress site I am trying to mail() the output of a function however it is failing to return the output but will return hard coded outputs placed inside the while loop.

Essentially what I am asking is what in this code is wrong and how do I fix it. I would rather be tutored in what I have done wrong than "Have fixed code; copy and paste" if at all possible.

I am purposely trying to stay away from inbuilt WordPress functions and calls

EDIT: When I echo $string; it displays with the expected output formatted as I intended, with the exclusion of the contents between ob_start() and ob_end_clean().

The functions are fetching the data properly it just is not being included in the email to be sent out, which is being sent it just appears blank. When sent as plaintext the email contents are as follows

<html><br /><br /></html>

Updated Code

I just inspected the output of the code, with the intent of displaying it to you so you can see the outcome and I noticed that this is included in-place of all the outputted emails, due to a "bonus feature" of one of my plugins, I am not sure which one, as this is nothing I have coded. Included inline due to not meeting reputation requirements to post more than two hyperlinks.

<p>[email protected]<script type="text/javascript"> /* <![CDATA[ */ (function(){try{var s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})(); /* ]]> */ </script><br> <br> </p>

To the best of my knowledge scripts cannot be run in emails, but surely this would not cause a failure to display the rest of the code, just render the scripts useless.

Expected Output

2
  • Which function(s) is misbehaving? Commented Nov 14, 2011 at 7:07
  • Please insert relevant code snippets inside the question itself as well, for the record, and to make it easier for users to see what might be wrong Commented Nov 14, 2011 at 7:11

1 Answer 1

1

On line 34:

mail($to, 'Test', $string, $headers) ;

should be

$sent = mail($to, 'Test', $string, $headers) ;

That's why it keeps saying the mail is not sent. It has been sent but you didn't set the variable you are checking.

Sign up to request clarification or add additional context in comments.

5 Comments

I am aware of that, I removed that thinking that the variable may not be being called.
Your code is too long and messy to wade through in an attempt to fix your problem. I recommend you try to narrow it down by checking what it is doing after every step by outputting to the browser. Then when you've narrowed it down you can post a new question with the specifics. Right now it's just a big mess of someone else's code that doesn't work.
I am unsure what you mean by my code being messy, I have tried to keep it as simple as I can however I am relatively new to coding and as such haven't mastered writing the most elegant code yet. Have you any suggestions on how to de mess it?
I mean more that you've just directed people to an entire script where there is somewhere an error, instead of narrowing it down to ask a specific question, which is the reason why you haven't received many responses.
I thought the question was self evident; "What is wrong with this code?" When I echo it, it displays but when I email it; nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.