Jump to content

Sending a Text


Beylah

Recommended Posts

$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.

 

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.