Conditional Causes Code to Fail
<p>I am writing a small email-to-text script, and it seems that every time I wrap the "doMail()" function in an if-statement, it fails, or within the function, if I wrap the mail() function with an if-statement, it also fails.</p>

<p>However, if I remove the conditionals, it works like a charm?  What should I do and what could be the cause of this?</p>

<p>EDIT: By "...it fails," I mean it echoes "Something went wrong!" just as it should according to the code.</p>

<p>Here is the code:</p>

<pre><code>&lt;?php
error_reporting(E_ALL);
session_start();
if (!$_SESSION['doesExist'] == true) 
    {
        echo "Session doesn't exist!";
        die();
    }

if (!isset($_POST['num']) || !isset($_POST['carrier']) || !isset($_POST['msg'])) 
    {
        echo "Failed!";
        die();
    }

$num = $_POST['num'];
$car = $_POST['carrier'];
$msg = $_POST['msg'];
$subject = '';
$head = 'From: admin@google.com' . "\r\n";

switch ($car)
    {
        case "att":
            $num .= "@txt.att.net";
            break;
        case "verizon":
            $num .= "@vtext.com";
            break;
        case "tmobile":
            $num .= "@tmomail.net";
            break;
    }

function doMail($toNum, $sub, $message, $headers)
    {
        if(mail($toNum, $sub, $message, $headers))
            {
                echo "Done!";
            }
        else
            {
                echo "Something went wrong!";
            }
    }

doMail($num, $subject, $msg, $head);

?&gt;
</code></pre>
