Jump to content

[SOLVED] mail() function randomly stopped working


Recommended Posts

First off, hello everyone.  This is my first post to this forum. 

 

The problem that I am having is that I have a page that uses the mail() function.  The page is on admin panel of a store and is called from another page that lists all of the orders.  Basically, the script updates the status of the order to indicate that the payment has been received and sends an email to the customer to notify them of the payment receipt.  The script was working fine for months, but recently stopped working completely.  (Although no error is thrown.)  The only thing that I can think that could have affected this is that the host recently upgraded from PHP 4 to PHP 5; however, I have another site on the same account where the mail function works just fine.  Any ideas?

 

Here's the code:

 

include "../globalvariables.php"; //just some global variables like the HTML for the header and footer of the email
$orderid = $_GET[iD];  //order ID passed in the URL
$customer = $_GET[C];  //customer ID passed in the URL
//update order (marks order as "payment received"
$query = "UPDATE orders SET status='2' WHERE ID='$orderid'";
$result = mysql_query($query) or die ("DB-fout:".mysql_error());

//mail customer
$querymail = "SELECT fname, lname, email FROM customers WHERE ID = $customer";
$resultmail = mysql_query($querymail) or die ("DB-fout:".mysql_error());
$rowm = mysql_fetch_array($resultmail);

$customermail = $mailheader;
$customermail .= "Dear $rowm[fname] $rowm[lname],<br><br>";
$customermail .= "We have received the payment for your OrderID $orderid. Your package will be shipped as soon as possible.<br>";
$customermail .= $mailfooter;

$to = "$rowm[email]"; 
$subject = "Payment received for Order $orderid";
$headers = "MIME-Version: 1.0\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
$headers .= $headersfrom;
mail($to, $subject, $customermail, $headers);

header("Location: packages.php"); 

 

Thanks!!!

 

Chris

$headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
$headers .= $headersfrom;
mail($to, $subject, $customermail, $headers);

 

Where does $headersfrom come to?

 

Try changing mail to this to the top of every page:

ini_set('display_errors', 1);

error_reporting(E_ALL);

 

Then change the mail() line to:

if(mail($to, $subject, $customermail, $headers)){
   headers('Location: packages.php');
}else{
   print "$to - $subject - $customeremail - $headers";
   die();
}

Your page might not redirect to packages.php but you will be able to debug.

Did you add the error_reporting code? You should see errors if you're not getting the mail.

 

Also, have you looked at the mail() function's other arguments? I have to use '-f-me@mail.com' in order to avoid spam filtering on the outgoing server.

Nevermind.  Finally got a reply from my host.  They transferred all the files to a new server and, in the process, changed all of the permissions.  I just chmod'ed it back to 755 and it works fine now.

 

Thanks again for your help everyone!!!

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.