0

I have a mail function

 $to = "fahad@somewhere.com";
 $subject = "Voucher Number: ".$voucher;
     $message = '<html><body>';
     $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
     $message .= "<tr style='background: #eee;'><td><strong>Voucher#:</strong> </td><td>" . strip_tags($voucher) . "</td></tr>";
     $message .= "<tr><td><strong>Name:</strong> </td><td>" . strip_tags($name) . "</td></tr>";
     $message .= "<tr><td><strong>Phone Number:</strong> </td><td>" . strip_tags($product) . "</td></tr>";
      $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($email) . "</td></tr>";


//set content-type
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <livingdeal@overstock-king.com>' . "\r\n";
$headers .= 'cc:'. $email . "\r\n";

mail($to,$subject,$message,$headers);

For some reason I'm not getting any mail sent at all. The service is hosted so i'm not running it from localhost, and even when I write

if (mail(....))
{ echo "success";
}
else { echo "failed"; }

I always get success, so my suspicion is that it is a problem on the server end. If php mail goes from port 25 is there any way to change the port to a different one in the script? or would it be in php.ini.

Also, would I be able to use a different server (that has a different domain) to send the mail without redirecting the use to that other webpage? I guess in other words can I connect to an smtp server through a php script before sending the mail?

Christian Rau
  • 45,360
  • 10
  • 108
  • 185
maestro416
  • 904
  • 2
  • 17
  • 31

2 Answers2

0

Mail() doesn't send mail, it submits it to the server's mail daemon for sending. If it returns true, that merely means that it was successfully submitted to the queue.

You need to look at the logs of your mail daemon to determine if the messages are in the queue, if they were actually sent, and if not, what error messages were logged when the message failed to send.

BTW, the machine is running a mail daemon, right?

GordonM
  • 31,179
  • 15
  • 87
  • 129
0

Check with your host, many shared hosting companies are disabling the mail() function to reduce spamming.

you need to be using smtp instead.

apps like wordpress have a simple plugin to handle this change.