我正在写一个小的电子邮件到文本脚本,似乎每次我在if语句中包装“doMail()”函数,它失败,或者在函数内,如果我包装邮件(使用if语句的函数,它也失败。
然而,如果我删除条件,它就像一个魅力?我该怎么做以及可能是什么原因?
编辑:通过“......它失败了”,我的意思是它回应“出了问题!”正如它应该根据代码。以下是代码:
<?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);
?>