Monday, 15 July 2013

php - Conditional Causes Code to Fail -



php - Conditional Causes Code to Fail -

i writing little email-to-text script, , seems every time wrap "domail()" function in if-statement, fails, or within function, if wrap mail() function if-statement, fails.

however, if remove conditionals, works charm? should , cause of this?

edit: "...it fails," mean echoes "something went wrong!" should according code.

here 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: 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); ?>

apparently according comment mail() function may homecoming empty string instead of boolean value of true , such evaluated false in conditional statement empty value considered false.

php

No comments:

Post a Comment