adam291086 Posted January 4, 2008 Share Posted January 4, 2008 I have a mail script. The problem is the echo message ''Mail Failed'' is always echoed. The emails are still being sent. Any ideas <?php // db properties $dbhost = ''; $dbuser = ''; $dbpass = ''; $dbname = ''; $conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($dbname); $conn; $sql = "SELECT * FROM generalContact"; $result = mysql_query("$sql"); while($row = mysql_fetch_array($result)) { $message = $row['Message']; $email = $row['email']; $subject = $row['subject']; $name = $row['firstName']; } echo $email; echo $subject; echo $message; echo $name; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'To: '.$name.' <'.$email.'>,' . "\r\n"; //This is the TO name and Email $headers .= 'From: Adam<[email protected]>' . "\r\n"; // This is YOUR name and email if(mail($email, $subject, $message, $headers)){ echo "Mail has been sent"; }else{ echo "Mail Failed"; } ?> Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 4, 2008 Share Posted January 4, 2008 Add the following to the start of your code to see if there are any errors returned by the mail() function call - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430460 Share on other sites More sharing options...
adam291086 Posted January 4, 2008 Author Share Posted January 4, 2008 tried that already and i get nothing Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430461 Share on other sites More sharing options...
revraz Posted January 4, 2008 Share Posted January 4, 2008 Does it ever echo success? You could try doing something like $success=mail($email, $subject, $message, $headers); echo $success; //and see what outputs Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430466 Share on other sites More sharing options...
adam291086 Posted January 4, 2008 Author Share Posted January 4, 2008 it does echo success. if(mail($email, $subject, $message, $headers)){ echo "Mail has been sent"; }else{ echo "Mail Failed"; } Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430468 Share on other sites More sharing options...
revraz Posted January 4, 2008 Share Posted January 4, 2008 So it echos success and failed at the same time, or just sometimes it says failed even though it worked? Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430471 Share on other sites More sharing options...
adam291086 Posted January 4, 2008 Author Share Posted January 4, 2008 it always says fails. Then i get an email. I did amuse me when 20 email arrived as i kept changing things to correct it. Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430473 Share on other sites More sharing options...
revraz Posted January 4, 2008 Share Posted January 4, 2008 Wait, right above you said it echo's success...? Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430474 Share on other sites More sharing options...
Sulman Posted January 4, 2008 Share Posted January 4, 2008 Have you tried: $result=mail($email, $subject, $message, $headers); if($result) { echo "Mail has been sent"; } else { echo "Mail Failed"; } ? Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430477 Share on other sites More sharing options...
adam291086 Posted January 4, 2008 Author Share Posted January 4, 2008 yep i have just tried that and still get Failed echo Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430481 Share on other sites More sharing options...
Sulman Posted January 4, 2008 Share Posted January 4, 2008 Are you running this on windows? Only this is mentioned on http://uk.php.net/manual/en/function.mail.php Note: The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine). Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP. As such, the to parameter should not be an address in the form of "Something <[email protected]>". The mail command may not parse this properly while talking with the MTA. Link to comment https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.