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<adam@adamplowman.co.uk>' . "\r\n"; // This is YOUR name and email if(mail($email, $subject, $message, $headers)){ echo "Mail has been sent"; }else{ echo "Mail Failed"; } ?> Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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"; } Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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...? Quote Link to comment 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"; } ? Quote Link to comment 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 Quote Link to comment 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 <someone@example.com>". The mail command may not parse this properly while talking with the MTA. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.