Reputation:
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.
However, if I remove the conditionals, it works like a charm? What should I do and what could be the cause of this?
EDIT: By "...it fails," I mean it echoes "Something went wrong!" just as it should according to the code.
Here is the code:
<?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: [email protected]' . "\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);
?>
Upvotes: 2
Views: 84