Beylah Posted June 8, 2017 Share Posted June 8, 2017 $now = strtotime("now"); $testtime = strtotime("$starttime"); if ($testtime <= $now && $delivered=="") { mail('1234567890@pcs.rogers.com', '', 'Request '.$id.' is due and has not been set up', 'name@email.com'); } I am trying to send a text if an order is not completed on time. I have tested the if statement and it is working but the text does not go through. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted June 8, 2017 Share Posted June 8, 2017 You can start by seeing whether mail() returns true or false. Is mail() failing or is the message just not making it through the SMTP servers? You're not checking. Your fourth parameter is not a valid email header. That could be causing mail() to fail. Quote Link to comment Share on other sites More sharing options...
Beylah Posted June 8, 2017 Author Share Posted June 8, 2017 I did test and the bool returned true - also the email address and phone number were altered to protect the user. Questions back: 1. how do I test the mail() 2. why is the 4th parameter not a valid email header (is it just because I changed it to hide the users identity) Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 8, 2017 Share Posted June 8, 2017 Throw away the mail() function and use a proper mail library like PHPMailer. The mail() function is far too low-level for the average programmer. It requires a deep understanding of both the e-mail message format and the underlying transport mechanism, and you clearly don't have that (which is fine). Without this knowledge, you won't have much success. This forum alone is full of mail()-related problems. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted June 8, 2017 Share Posted June 8, 2017 mail() "returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise." Check out the manual page for examples if you're not sure what an email header is. http://php.net/manual/en/function.mail.php Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 8, 2017 Share Posted June 8, 2017 (edited) Aside from Jacques1's advice, which you should follow, just because an email isn't received doesn't mean it wasn't sent. That is a bad idea. Many things can cause an email to get rejected somewhere along the way from the sender to the intended recipient. You are using an empty subject which is a bad idea right off the start. Try to ensure the emails are complete and do not include any content that could trigger any spam protection. One possible problem you may have is that some email protection checks the sending email address domain and the originating sending server to see if that server is the authorized server for that domain. If it isn't the email may be dropped. This is to prevent spammers or malicious users from sending emails that impersonate a legitimate entity. 2. why is the 4th parameter not a valid email header (is it just because I changed it to hide the users identity) Because the 4th parameter is for all headers, not just the sending address. A cursory look at the manual would have shown you that $to = 'nobody@example.com';$subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); Edited June 8, 2017 by Psycho Quote Link to comment Share on other sites More sharing options...
Beylah Posted June 9, 2017 Author Share Posted June 9, 2017 $now = strtotime("now"); $usetime1 = strtotime("$starttime"); $usetime2 = strtotime("+30 minutes"); require 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->setFrom(name@host.com', 'name'); $mail->addAddress('name@host.com', 'name'); $mail->Subject = 'Warning'; $mail->Body = 'Request '.$id.' is due and has not been set up.'; if(!$mail->send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } if ($admindelivered1 == '' && $cancelled != 'x' && $usetime1 <= $now) { $mail->Send(); } I have tried using the PHPMailer suggested above and still no luck. I downloaded the folder and put it on my server with the page with the above code it and no email was sent. Thanks everyone for you help Quote Link to comment Share on other sites More sharing options...
Sepodati Posted June 9, 2017 Share Posted June 9, 2017 Did you get an error message or did the email just not show up? There's an obvious syntax error with a missing single quote around name@host.com, but hopefully that's just a copy/paste error? -John Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 9, 2017 Share Posted June 9, 2017 You should use an external SMTP server for testing (Gmail or whatever) instead of your own, because obviously there's something wrong with your server. You also need to enable exceptions, turn your error reporting all the way up and make sure that the errors are logged, so that you can tell us more than "it doesn't work". Get the code right. Then we can talk about setting up your own mail server. Quote Link to comment Share on other sites More sharing options...
Beylah Posted June 9, 2017 Author Share Posted June 9, 2017 I have my errors turned on and I did not receive any errors and no I did not receive the email Quote Link to comment Share on other sites More sharing options...
Beylah Posted June 9, 2017 Author Share Posted June 9, 2017 I have tried again and I get "Message has been sent" the only thing I can think of is that it is an internal server and the page is running on an intranet and that there is some kind of block. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 9, 2017 Share Posted June 9, 2017 You can speculate all day long about what might be the problem. Or you can approach the problem systematically. As I've already told you, the first step is to make the code work with an external, known good mail service like Gmail. When the mail goes through Gmail, you at least know that the PHP script itself is valid. Then you can start debugging your own server. Be warned that running a local SMTP server requires solid sysadmin knowledge -- which you don't seem to have. You need to get the configuration right, set up various anti-spam techniques to be accepted by other mail servers, possibly adjust the firewall rules, find out how local clients can interact with the service etc. This isn't as easy as clicking a "send" button. 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.